Есть небольшое недопонимание
Есть код
$ cat test.py
#!/usr/bin/python
class A:
def test(self):
print urllib
if __name__ == '__main__':
import urllib
a=A()
a.test()
$ python test.py
<module 'urllib' from '/usr/lib/python2.7/urllib.pyc'>
$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> from test import A
>>> a=A()
>>> a.test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.py", line 6, in test
print urllib
NameError: global name 'urllib' is not defined