2.1.1 global weirds

Robin Becker robin at jessikat.fsnet.co.uk
Sat Aug 11 12:24:00 CEST 2001

I have difficulty in understanding why the 
 print n, len(getStory()), len(_story)
always prints n, 0, 0

why is b2.getStory not getStory? Is it because importing from a isn't
the same as the importing from the __main__ module?

What is the correct way to import from the main script?

when I run a.py I see
0 0 0
1 0 0
2 0 0
[1, 2]

_story = []

def getStory():
        return _story

def func(n):

def run():
        print 0, len(getStory()), len(_story)
        import b1
        print 1, len(getStory()), len(_story)
        import b2
        print 2, len(getStory()), len(_story)
        print b2.getStory()
        print b2.getStory is getStory

if __name__=='__main__':

from a import getStory, func

from a import getStory, func
Robin Becker

More information about the Python-list mailing list