What ought to persist after a program is run?
Thomas Philips
tkpmep at hotmail.com
Wed Jun 16 14:49:48 EDT 2004
Here's a very simple program with an odd twist:
class Player(object):
def __init__(self,name):
self.name = name
hero = Player("A")
print "hero",hero
If I run it in IDLE and then type dir() at the prompt, I get
>>>['Player', '__builtins__', '__doc__', '__name__', 'hero']
However, if I modify the program as follows
class Player(object):
def __init__(self,name):
self.name = name
def main():
hero = Player("A")
print "hero=",hero
main()
and then run it in IDLE and type dir at the prompt, I get
>>>['Player', '__builtins__', '__doc__', '__name__']
Why does 'hero' not appear in the workspace directory when main() is
invoked and vice versa?
Thomas Philips
More information about the Python-list
mailing list