PDA

View Full Version : how to run python



T-AA
November 2nd, 2006, 03:39 PM
Hello how would i run this?

i'm very new to this


#!/usr/bin/ python

friend_list = ['liz' , 'tom' ,'Ralph']

print friend_list


I wrote this in kate(kubuntu dapper), and saved it as first.pyw.
Along with that file i got another one called first.pyw~, now when i open this i just get the konsole at tom@centurion... but nothing else happens.

duff
November 2nd, 2006, 04:35 PM
First make it executable, then run it.

# chmod +x first.pyw
# ./first.pyw

rplantz
November 2nd, 2006, 05:08 PM
Hello how would i run this?

i'm very new to this



I wrote this in kate(kubuntu dapper), and saved it as first.pyw.
Along with that file i got another one called first.pyw~, now when i open this i just get the konsole at tom@centurion... but nothing else happens.

In addition to duff's comment, you have a typo in your program.


#!/usr/bin/python

tells the system to send what follows to the program /usr/bin/python. Notice that you have a space between "/" and "p".

In addition, you can use the command


which python

to make sure your python is indeed located at /usr/bin/python. If not, then use your location.

Also, the first.pyw~ file got generated by your editor, kate, when you changed first.pyw. Many editors do that for you automatically. It gives you one level of backup. In case you really mess up a file when you are editing it, take a look at the "~" version of it. You can "undo" all your new changes with the command


mv somefile~ somefile

(It's best to do things like this when you're not tired, in a rush, etc. :))

tseliot
November 2nd, 2006, 06:01 PM
In addition to duff's comment, you have a typo in your program.


#!/usr/bin/python

tells the system to send what follows to the program /usr/bin/python. Notice that you have a space between "/" and "p".

Shouldn't it look like this?

#!/usr/bin/env python

tseliot
November 2nd, 2006, 06:02 PM
First make it executable, then run it.

# chmod +x first.pyw
# ./first.pyw

OR you might just type this:

python first.pyw

rplantz
November 2nd, 2006, 07:21 PM
Shouldn't it look like this?

#!/usr/bin/env python


Oops. Thank you for correcting my error.

T-AA
November 3rd, 2006, 07:57 PM
thx guys will give at try when i got the time

kurhula.com
July 28th, 2009, 10:32 AM
OR you might just type this:

python first.pyw

I'm new to both Python and Jython and was looking around for instructions on how to run Jython. I tried tseliot's suggestions but it just wouldn't work! chmod +x myprogram.extension seemed to work but when I ran ./myprogram.extension, I got the error "unexpected token '('". I then tried the other suggestion: python myprogram.extension, which returned the error "ImportError: No module named javax.swing". Out of desperation, I changed the 'p' into a 'j' and the rest is history!

JordyD
July 28th, 2009, 05:41 PM
I'm new to both Python and Jython and was looking around for instructions on how to run Jython. I tried tseliot's suggestions but it just wouldn't work! chmod +x myprogram.extension seemed to work but when I ran ./myprogram.extension, I got the error "unexpected token '('". I then tried the other suggestion: python myprogram.extension, which returned the error "ImportError: No module named javax.swing". Out of desperation, I changed the 'p' into a 'j' and the rest is history!

That's because this is a Python thread, not a Jython thread. And it's 3 years old.