How to use a variable form main script in a module.

Darrell news at dorb.com
Tue Jul 27 17:37:41 EDT 1999


import sys
main= sys.modules['__main__']
main.setDebug(__name__)

larsga at ifi.uio.no (Lars Marius Garshol) wrote in 
<wkg12bscly.fsf at ifi.uio.no>:

>
>* Peter Torstenson
>|
>| This is probaly a silly question from a newbie.
>| In my main script I put a value for to a variable called "x".
>| Now I want to use the "x" variable in a module.
>| The module is imported into the main script. How to do this?
>
>From the way you describe it this sounds like something you shouldn't
>do. Communication between different pieces of code through globabl
>variables is in general frowned upon, and with good reason. It's good
>for some things, but for those the variables tend to reside in a
>module, and not in the global namespace.
>
>Feel free to explain the reason why you want this if you want a
>verdict on whether it's a good or bad idea.
>
>[...wrong info in previous version of this post removed (global
>doesn't work)...]
>
>--Lars M.
>





More information about the Python-list mailing list