Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 19 Online
OpenStudy (anonymous):

Please forgive me if this is too basic...I'm running Python in Linux. It's already installed and I open it through a terminal and not a separate IDLE. I've written my first program, but I don't know how to test it. I don't know how to get Python to look for it in the right place. Does that make sense?

OpenStudy (s3a):

Does cd /the/dir/it/is/in and then python3 filename.py work?

OpenStudy (anonymous):

Yeah, as s3a said you can run it with "python filename.py"

OpenStudy (s3a):

Also, on Debian, I'm pretty sure "python" uses whatever is default but if you use the "python2" or "python3" command, you get to explicitly choose which version you use.

OpenStudy (anonymous):

If I assume you've got a textfile with your python program, you can run it from the python console by calling `execfile( "program.py" )` (or e.g. `execfile( "../test/program.py" )` ). You can also simply call `python program.py` from your terminal. Another way, which is the way I usuallt prefer, is by putting a line in front of your script that tells the terminal how to execute it. You can then simply run your program from the terminal (e.g. ./program.py) if you make it executable. The line will be something like `#!/usr/bin/python` (and it should be the first line in your file). This will also work for perl/ruby/bash scripts.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!