[Tutor] how to run a text file in an interpreter?

Andreas Kostyrka andreas at kostyrka.org
Fri Mar 30 19:13:44 CEST 2007


* Tonu Mikk <tmikk at umn.edu> [070330 18:52]:
> I started reading Instant Python tutorial ( 
> http://hetland.org/writing/instant-python.html ) and came across this 
> section:
> "/Note:/ To get the examples working properly, write the programs in a 
> text file and then run that with the interpreter; do /not/ try to run 
> them directly in the interactive interpreter - not all of them will work. "
> 
> I do not know what the author means by running a text file with the 
> interpreter. I noticed that I came across an obstacle early on in trying 
> out the code.
> 
> I tried writing
> 
> |first, second = second, first
> 
> into the PythonWin interpreter, but this resulted in the following error after pressing the return key:
> 
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> NameError: name 'second' is not defined
> 
> I imagine that I need to create a text file first and then run it with the interpreter.  How do I do that?

Well, you did not mention your platform, but in this case, the
interactive one should do:
first = 1
second = 2
first, second = second, first

About these file thing:

Write your code to a file named ending in .py, and then call it as
python yourname.py

Andreas


More information about the Tutor mailing list