Re: strings in the global section

2006-10-12 Thread Bjoern Schliessmann
Tim Chase wrote: > Sounded like the OP wanted a behavior similar to "auto-globals" > that has been a long-cursed aspect of PHP. That, without > specifying it, local-variables should be global if their name > exists in the global namespace. Sounds like a source of many hard to track down bugs.

Re: strings in the global section

2006-10-12 Thread Tim Chase
>> Works, but something different ? > > Excuse me, what do you mean? Sounded like the OP wanted a behavior similar to "auto-globals" that has been a long-cursed aspect of PHP. That, without specifying it, local-variables should be global if their name exists in the global namespace. Python s

Re: strings in the global section

2006-10-12 Thread Bjoern Schliessmann
Phoe6 wrote: > #!/usr/bin/python > global astring > astring = "This is a String" A global declaration just says "look for this name in the module namespace". Since you /are/ in the module namespace here, there's no need to put "global" here. > Works, but something different ? Excuse me, what d

Re: strings in the global section

2006-10-12 Thread Phoe6
Bjoern Schliessmann wrote: > If you assign "astring" inside the function body, it's a local name. > > > - What should I do to overwrite the string variable in the global > > section within functions? > > Put a "global astring" in the function to access the global name > instead. #!/usr/bin/python

Re: strings in the global section

2006-10-12 Thread Tim Chase
Phoe6 wrote: > I write a script: > #!/usr/bin/python > astring = "This is a String" > > def fun1(): > astring = "I modify it in fun1" > def fun2(): > astring = "I modify it in fun2" > def main(): > print astring > fun1() > print astring > fun2() >

Re: strings in the global section

2006-10-12 Thread Bjoern Schliessmann
Phoe6 wrote: > But it is not so. It always prints This is a String. astring > declared outside all the functions, is not in global section and > values be overwritten by functions accessing it? > > - How is this working? If you assign "astring" inside the function body, it's a local name. > -

strings in the global section

2006-10-12 Thread Phoe6
I write a script: #!/usr/bin/python astring = "This is a String" def fun1(): astring = "I modify it in fun1" def fun2(): astring = "I modify it in fun2" def main(): print astring fun1() print astring fun2() print astring if __name__ == '__mai