Perl to Python: Variable Scope

In Perl all variables are by default global. You can use my to define a variable as local. Then the variable is local within a scope that is defined by curly braces ( { ... } ).

In Python however a variable's scope is defined by the structure where you first use it. If you need a variable to have a wider scope you need to define the variable in the scope where you need it.

Careful: a for loop does not introduce a new scope. Variables inside a loop are not local.

WorkaroundOrg: PerlToPython/VariableScope (last edited 2005-08-29 18:27:34 by ChristophHaas)