[Tutor] IDLE and __name__, variables, etc.

Alfred Milgrom fredm at smartypantsco.com
Mon Nov 10 22:32:45 EST 2003


Hi:

I wonder what I am doing wrong with my configuration of IDLE on Windows. My 
version of IDLE is IDLE 0.8, and I am running Python 2.2.

If I try the usual structure of
if __name__ == "__main__":

then my programs don't run.

By using
print __name__
I have found that __name__ is set to the filename (less the ".py" 
extension), such as 'test' (when I save my program as test.py).

As well, it used to be that after running my programs I could use the 
Python shell to see the values of various variables  in my program or test 
individual subroutines. Now it comes up with "NameError: name 'a' is not 
defined", and I have to use 'test.a' to do view the variables.

How do I set the behaviour back to be able to use the __name__ trick?

In my file association, .py file are set to open using IDLE by the command:
C:\PYTHON22\pythonw.exe C:\PYTHON22\Tools\idle\idle.pyw  -e "%1"

Thanks in anticipation,
Fred Milgrom





More information about the Tutor mailing list