Can we make a local variable in a function as global variable???

Steven Howe howe.steven at
Thu Apr 5 17:35:12 CEST 2007

sairam wrote:
> I have some local variables defined in one method and Can I make those
> variables as global variables? If so , can any one explain me how can
> I do that
> Thanks,
> Sairam

When a line of code asks for the value of a variable x, Python will 
search for that variable in all the available namespaces, in order:

   1. local namespace - specific to the current function or class
      method. If the function defines a local variable x, or has an
      argument x, Python will use this and stop searching.
   2. global namespace - specific to the current module. If the module
      has defined a variable, function, or class called x, Python will
      use that and stop searching.
   3. built-in namespace - global to all modules. As a last resort,
      Python will assume that x is the name of built-in function or

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list