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.
Thank you.
And how would I do that?Compile them with python?
You don't. I don't know why he said that.And how would I do that?
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:
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.Code:#!/usr/bin/env python import cgi print "Content-type: text/html" print print "Hello World"
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).