zjm_code |
in a.py:
c='ccc'
in b.py:
import a print dir(a)
when I execute b.py it shows (it imports the folder 'a'):
['__builtins__', '__doc__', '__file__', '__name__', '__path__']
and when I delete the folder, it will show (imports a.py):
['__builtins__', '__doc__', '__file__', '__name__', 'c']
so my question is:
how to import a.py through do not delete the folder
thanks
updated
I am using imp.load_source, so in b.py there is:
import imp,os path = os.path.join(os.path.dirname(__file__), os.path.join('aaa.py')) ok=imp.load_source('*',path) print ok.c
now it's ok and type 'ccc'
and
how to show 'ccc' via "print c" not via "print ok.c" ???
thanks
updated2
now this is normal:
imp.load_source('anyname',path) from anyname import * print c
he shows 'ccc'
updated3
this is also normal:
import imp,os imp.load_source('anyname','aaa.py') from anyname import * print c
source share