[Tutor] Instances

Terje Johan Abrahamsen terjeja@hotmail.com
Fri, 19 Jul 2002 14:49:04 +0000


I want to create a program that runs as an .exe file with py2exe or similar. 
In order to do so, the program has to create an instance of itself.

Hopefully this can show you what I want:

class test:

    n = test()
    choice = 0

    def __init__(self):
        test.choice = int(raw_input("What do you want to print? 1)Hello or 
2)Hey : "))
        if test.choice == 1:
            n.hello()
        else:
            n.hey()

    def hello(self):
        print"Hello"

    def hey(self):
        print"Hey"

But, it doesn't work. I get the following error: NameError: name 'test' is 
not defined. In other words, I have to write n = test() myself in the IDLE 
window. But, if it is an .exe file, I cannot write that. So, usually I have 
made a runme.py script that just contains:

from test import *
n = test()

But, this solution doesn't seem to work all the time either. How can I 
modify the first script to work?

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com