How to use python?

the_king_dollars

New Member
Messages
153
Reaction score
0
Points
0
Can you tell me how to actually use python scripts? Please if you know tell me step by step.
Thank you.
 

noerrorsfound

New Member
Messages
1,736
Reaction score
1
Points
0
And how would I do that?
You don't. I don't know why he said that.

Python is an interpreted language just like PHP, so you just upload the script in source form.

Here is a very helpful response by Richard:
Just a couple of things. When using python cgi you need to import the cgi module also because you are working with web documents you need to tell what type of document header it needs to use.

So... The code will look as follows:
Code:
#!/usr/bin/env python

import cgi

print "Content-type: text/html"
print
print "Hello World"
Line 1: The shebang (#!/usr/bin/env python) - this line uses the env command some times python is not installed in /usr/bin. This command looks in several location for a python installation.

Line 3: Import the cgi module so that it can be use via the web.

Line 5 + 6: Here we tell the browser that the page is text and formated as html the secont print command seperates the header from the reast of the script. With out it the script fails.

Line 7: We print Hello World

Using python out side cgi-bin

If you want to use python files outside cgi-bin or use the .py file extention you need to goto Apache Handlers in cPanel can add .py (or any other extention) and cgi-script in the two boxes provided. This will allow you to execute cgi files anywhere on your site (BTW: .cgi is set by default).

Edit: I noticed that I assumed you were talking about running Python scripts on your site. To run a Python script on your computer just make sure Python is installed and double click the script.
 
Last edited:
Top