Python __import__ parameter confusion

Posted by CMC on Stack Overflow See other posts from Stack Overflow or by CMC
Published on 2010-05-30T18:45:24Z Indexed on 2010/05/30 18:52 UTC
Read the original article Hit count: 308

Filed under:
|
|
|

I'm trying to import a module, while passing some global variables, but it does not seem to work:

File test_1:

test_2 = __import__("test_2", {"testvar": 1})

File test_2:

print testvar

This seems like it should work, and print a 1, but I get the following error when I run test_1:

Traceback (most recent call last):
  File ".../test_1.py", line 1, in <module>
    print testvar
NameError: name 'testvar' is not defined

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about python

Related posts about import