It's pretty typical for scoping rules. If you define variables outside of your funcs you can access them inside the func. If you want to change the value in the function you need to declare the scope as global. If you make another variable with the same name inside of a function it will shadow the outer variable. You could define the variables in a parent script if you want. This is actually how imports work basically.
In config.py foo = "bar" In your py from config import foo def bar(): print foo ----------------------------- Sent from a mobile device with a bad e-mail client. ----------------------------- On Nov 10, 2010, at 12:21 PM, Jeff Honey <je...@pona.net> wrote: > I have a question about where variables are exposed in python. > > I have a monolothic script with a number of functions defined, can those > functions share variables? can I instantiate them outside the function of > where they are needed? do they need to be wrapped in quotes, ever? For > example: > > blah = 123 > foo = 'somestring' > > def function(foo): > code that needs foo > anotherfunction(blah) > > def anotherfunction(blah): > code that needs blah > code that uses foo > > ....how about this: > > def function(blah, foo): > anotherfunc(blah) > anotherfunc(foo) > > ...what about my python being called from some parent script (something OTHER > than python) that instantiates blah and foo FOR me? Can I just plug those > into my code like I would normally? I guess this is more about HOW and WHERE > I can make variables available for use. > > -- > ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ > ¤ kyoboku kazeoshi ¤ > ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor