Running python scripts

Asked by Earl Porter on 2011-01-19

When I try to run a Python script (which is nothing but print commands of html tags) Firefox pops up the Downloads directory window and another window wanting to know what program I want to open the script (with gedit being the default). Firefox recognises that it is a Python file but doesn't automatically process it. Is there some thing I have to turn on in Firefox?

Question information

English Edit question
Ubuntu python-defaults Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
mycae (mycae) said : #1

Save the file to your home folder,

then open a terminal, and type

where "PYTHONSCRIPT" is replaced by the name of the python script (you should keep the quotes around the name if it has spaces in the name).

Make sure you know what the script does first -- there is nothing preventing it from deleting your user's files :).

Earl Porter (eporter1955) said : #2

The script is supposed to print something to the browser screen. It is simply html flags of html, head, title, body and heading. If I call the script with Safari browser it prints out the script. Other browsers want to save it or choose open method.

Best mycae (mycae) said : #3

>The script is supposed to print something to the browser screen.

The script should do no such thing.... The browser is a separate process, and should not be directly interpreting python; there is discussion on this topic throughout the interwebs. For example:

Python was always intended to be useful when it has normal OS level access.

>It is simply
>html flags of html, head, title, body and heading.

Just save-as if you want to execute it, or if you want to see the content, open it with gedit.

Just be mindful that just because a script says it does X, does not mean it actually does X -- one could easily slip in a:

if randint(0,100) == 10 :

and you would be safe 99 times out of 100.... 1 in 100 times though :)

So it might just be worth having a quick glance over the script for safety's sake.

Earl Porter (eporter1955) said : #4

Thanks mycae, that solved my question.