Does anyone have python on Win98???

Prateep Siamwalla teep at inet.co.th
Sun Jan 28 22:25:45 EST 2001


There are a couple of ways to running a python script from the command line.
I'll show you the
two i'm most familiar with.

the first way is simply write your python script as a series of statements.

try1.py
::::::::::::::::::::::::
myFile = open(r'c:\tmp\trythisout.txt','w')
myFile.write("Hello World\n")
myFile.close()
print "Finished!!"
::::::::::::::::::::::::
then on your command line type:
python try1.py

["python" needs to be in your path]
i just added this one line into my  c:\autoexec.bat
SET PATH=C:\PYTHON20
(yours seem to be c:\Programming\Python2 -- you might have to do that funny
dos formatting with the name c:\progra~2 or something. After you edit your
autoexec.bat, you'll need to restart the machine.)

the second way is to write your python script as a series of definitions and
include a "if __name__=="__main__" condition at the end

try2.py
:::::::::::::::::::::::
def myFunction(filename):
    myFile = open(filename,'w')
    myFile.write("Hello World\n")
    myFile.close()

if __name__=='__main__':
    myFunction(r'c:\tmp\trythisout.txt')
    print "Finished!!"
:::::::::::::::::::::::

again, you can type at the command line:
python try2.py

These are very trivial samples of the common ways of getting a python script
to run from the windows command line.

If you will be delving further into python on Win32, Mark Hammond's + Andy
Robinson's Oreilly book "Programming on Win32" is HIGHLY recommended.

Hope this has been helpful.

teep
shaka <fabrice.n at home.com> wrote in message
news:XY1d6.9583$KP3.3117045 at news3.rdc1.on.home.com...
>
>
>
> Ok, I need some help here.  I just download python on my computer.
> I installed it to     C:\programming\python20
>
> I know how to use the interactive mode.  And when write a script I usually
> run it from the editor(idle) by clicking on "run script".
>
> But when I try to run the script using the interpreter, it doesn't work.
> What I do is to type the name of the script.py in the interactive mode. It

> always give me an error message like:
>                         Traceback (most recent call last):
>                           File "<stdin>", line 1, in ?
>                         NameError: There is no variable named 'hello'
>
> Is the interpreter suppose to be in interactive mode everytime?
>
> If you have no idea of what I am talking about, can you just describe me
how
> you usually run your script.
>
>
>
>
>
>
>





More information about the Python-list mailing list