Page 1 of 1

Python Run help

Posted: Fri Jul 27, 2012 11:16 pm
by girmofdoom
I am not sure if this is the right section or not. I couldnt really find a specific one for it, but could someone help me. I am at the beggining of learning python, I created a file with just (only stuff inside the <>,not them itself) < Print "Hello World!" >, i save the file as, i double click it and it gives me options for opening it. the only 2 for running are "Run" and "Run in terminal". The "Run" does nothing when i try it, then i try "Run in terminal" and it only flashes the terminal for a half second then disappears. Could someone please help me. I want to learn python(ive prevoiusly learned HTML/5 and CSS/3).

Re: Python Run help

Posted: Sat Jul 28, 2012 3:01 am
by xenopeek
"Run" runs the program, but without showing a terminal. This is mostly useful for GUI applications. "Run in Terminal" runs the program and shows its output in a terminal, but the terminal is closed upon completion of the program. You will not see the output as it is done so quick.

Four alternatives to test your Python console programs:

1. Open a terminal yourself, go to the directory where you have your Python file and run it with:

Code: Select all


The output will show, and the terminal remains open and waiting for your next command. BTW this works only if you have given the file execute permissions.

2. Make your program wait for a key press before closing, and then just use "Run in Terminal". For Python 3 you can do so by adding the line at the end:

Code: Select all

input("Press Enter to continue...")

or for Python 2:

Code: Select all

raw_input("Press Enter to continue...")

3. Change the configuration of your terminal to not close once the program that is running on it closes. To do so for GNOME Terminal, go to Edit > "Profile Preferences", "Title and Command" tab, and then change "When command exits" to "Hold the terminal open".

4. Use a IDE to write your Python applications, and those usually have the option to run programs from within the IDE and show terminal output.

I just use the first option :wink:

Re: Python Run help

Posted: Sun Jul 29, 2012 10:36 am
by dritzominous
Putting this as the first line in your script might help:

Code: Select all

#!/usr/bin/env python

^ might be different if you're using python3; and it varies based on what OS you're running.

And you might have to edit the permissions to allow the file to execute:

Code: Select all

chmod +x ./

must be in the script's directory to do that exact command, unless you specify the file location.

Or, if you get lazy and don't want to do that, just:

Code: Select all