The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do you do a "hello world" in python

Discussion in 'General Discussion' started by randyvalpobb, Jun 14, 2005.

  1. randyvalpobb

    randyvalpobb BANNED

    Joined:
    Jun 8, 2005
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    I am looking for some information on how to do a "hello world" in python and have it run in a separate browser.
     
  2. Marty

    Marty Well-Known Member

    Joined:
    Oct 10, 2001
    Messages:
    630
    Likes Received:
    1
    Trophy Points:
    18
    Code:
    #!/usr/bin/python
    
    # Tell the browser how to render the text
    print "Content-Type: text/plain\n\n"
    
    print "Hello, Python!"  # print a test string
    
    Save that in a text file named hello.py

    Then link to it with target=_blank attribute to force a new window.

    You can get more info here:

    http://www.devshed.com/c/a/Python/Writing-CGI-Programs-in-Python/
     
  3. randyvalpobb

    randyvalpobb BANNED

    Joined:
    Jun 8, 2005
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    python code wont parse

    It is not parsing the python code for, hello world, when I add iit on a customer's website. It shows up as plain text. Do you know how I get the code to parse. He has 5 pages of code he is trying to get to parse with no success.

    Thanks
    Randy :eek:
     
  4. KatieBuller

    KatieBuller BANNED

    Joined:
    May 10, 2005
    Messages:
    65
    Likes Received:
    0
    Trophy Points:
    0
    I am also having this problem. How do we fix this?
     
  5. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Presumably, you're going to need to modify httpd.conf to recognise python scripts for CGI processing. Have you added a handler for .py files etc.? If not, then you'll need to do a net search on configuring python in apache.
     
  6. randyvalpobb

    randyvalpobb BANNED

    Joined:
    Jun 8, 2005
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    If possible, could you please tell me how to configure python in apache. Could you let me what I need to add in the apache.conf file.

    Thanks
    Randy :)
     
  7. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
  8. randyvalpobb

    randyvalpobb BANNED

    Joined:
    Jun 8, 2005
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Gracias Chirpy it works. We add an error with the python script 'Premature end of script". We find that invisible charaters will get put there. We deleted them and it works fine.

    Thanks a lot
    Randy
     

Share This Page