Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

python as cgi

Gregry2Gregry2 Posts: 607Member
I read that python is as capable as a cgi script as php and perl, and I would like to think so as well since I like python and noe it better than php or perl...but is it really true? What is python best for anyway?

{2}rIng

Comments

  • infidelinfidel Posts: 2,900Member
    : I read that python is as capable as a cgi script as php and perl, and I would like to think so as well since I like python and noe it better than php or perl...but is it really true? What is python best for anyway?

    Python is good for whatever you want to do with it, except for the kinds of things that any other interpreted language is not good at, like operating systems or low-level things like that.

    There are tons of examples on writing CGI in python. It even comes with a couple of libraries that help out.

    Technically you can write a CGI program in any language, so you might as well pick one that you like.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • Gregry2Gregry2 Posts: 607Member
    : : I read that python is as capable as a cgi script as php and perl, and I would like to think so as well since I like python and noe it better than php or perl...but is it really true? What is python best for anyway?
    :
    : Python is good for whatever you want to do with it, except for the kinds of things that any other interpreted language is not good at, like operating systems or low-level things like that.
    :
    : There are tons of examples on writing CGI in python. It even comes with a couple of libraries that help out.
    :
    : Technically you can write a CGI program in any language, so you might as well pick one that you like.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :

    I've never programmed in php or perl, and I'm not saying there are any differences, but does python have any edge vs. these langs in cgi?
    {2}rIng
  • infidelinfidel Posts: 2,900Member
    : I've never programmed in php or perl, and I'm not saying there are any differences, but does python have any edge vs. these langs in cgi?

    I'm not sure what kind of "edge" you're looking for. There's nothing really special about CGI. All CGI really means is that the webserver calls an external executable program each time that URL is requested, sets up the environment for it, and then reads that program's output to send back to the client. PHP is different because there's a module *in the webserver* that interprets the PHP code and renders the HTML output. There are also modules (for Apache, at least) that let you interpret Perl or Python code within the webserver process similar to PHP, but that is something else entirely from CGI.

    I know that Python comes with the cgi and cgitb modules which have some "helper" objects in them for getting things like form input and displaying pretty error tracebacks. I'm sure Perl has useful libraries that help with CGI stuff like that as well. Aside from HTTP-specific things like form input (which is ultimately nothing more than environment variables and standard input), a CGI program is just a regular program that writes output to stdout (in Python you use the "print" statement).

    So use what you know and like.

    If you want to do something where your python code is actually running in the server then I personally recommend CherryPy. There's also TurboGears which runs on CherryPy but comes with all kinds of extra stuff to get you started. The standard documentation that comes with Python explains the cgi and cgitb modules well enough to get started with simple CGI.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.