Can we make a local variable in a function as global variable???
Steve Holden
steve at holdenweb.com
Thu Apr 5 15:16:25 EDT 2007
Collin Stocks wrote:
> As for me, I find this problem annoying, but easy to solve. My solution is:
>
> >>> this=__import__(__name__)
>
> To set global variable spam to 4, I say:
>
> >>> this.spam=4
>
> This always works, and is much more convenient than:
>
> >>> global spam
> >>> spam=4
>
> and then worry about local variables also named spam.
>
That's truly horrible. And what if you have a local variable called "this"?
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
More information about the Python-list
mailing list