Question:
how do you run a program you wrote in python?
isWatitiS
2012-10-08 10:17:45 UTC
i wrote a program in a python window... not the one that has the ">>>" but just white background... not sure what its called:P i guess just a notepad?

so i saved it on my desktop as a .py file... how do i run it in python? (im on a windows 7 laptop if that helps)
Three answers:
Russel
2012-10-08 12:02:36 UTC
I may have had a slight bout of OCD or some just now but anyways, here's my answer.

http://pastebin.com/NTz3YdLd

Yahoo wasn't too appreciative of the length.
?
2012-10-08 21:50:25 UTC
The Python interpreter is usually installed as /usr/local/bin/python . Putting /usr/local/bin in your Unix shell's search path makes it possible to start it by typing the command.

python



You may be able to check where the python is installed by typing "which python".



You can put all your commands in a file with the extension 'file_name.py' and run it by

typing:



python file_name.py



Note that there is a difference between "python file" and "python


Python scripts can be made directly executable, like shell scripts, by putting the line (assuming the python path as used in the example above)



#! /usr/local/bin/python



at the beginning of the script and giving the file an executable mode. The "#!" must be the first two characters of the file. On some platforms, this first line must end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or Windows ("\r\n") line ending. Note that the hash, or pound, character, "#", is used to start a comment in Python.



The script can be given a executable mode, or permission, using the chmod command:



$ chmod +x myscript.py
David
2012-10-08 10:31:37 UTC
go to Start > All programs > Accessories and click on Command Prompt. then drag the python file from the explorer view into this command line and press Enter...



now you can watch the output of the script execution !


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...