Formatting Python output

Posted on 2014-09-12
Last Modified: 2014-09-13
The following is a cgi page which has been written in Python3.4.  It is the action page of a html form. The pages does process the form input and does give an output which is correct content wise. However it is not formatted correctly and looks like this :

Helloo ('james', 'KANE', '', '2014-09-09')!

I would like an output something like this :

Hello James Kane

If someone could take a look at the code below and fix the code and/or point me to some on line document it would be great !! Thanks for reading this.  jim

import cgi
def htmlTop():
             <DOCTYPE html>
             <html lang="en">
                  <meta charset="utf-8"/>
                  <title> My Server-side template</title>

def htmlTail():
def getData():
      formData = cgi.FieldStorage()
      firstname = formData.getvalue('firstname')
      secondname = formData.getvalue('secondname')
      youremail = formData.getvalue('youremail')
      birthday = formData.getvalue('birthday')
      return firstname,secondname,youremail,birthday
#main program

if __name__== "__main__":
            firstName = getData()
            print("Helloo {0}!".format(firstName))          

Open in new window

Question by:jameskane
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 35

Accepted Solution

Robert Schutt earned 500 total points
ID: 40320336
Try replacing line 31 with:
print("Hello {0[0]} {0[1]}<br/>\n{0[2]}<br/>\n{0[3]}<br/>\n".format(firstName))

Open in new window

LVL 35

Expert Comment

by:Robert Schutt
ID: 40320338
Couple of extra remarks:
- I added code tags to the code in your question to be able to refer to the line number
- there seems to be an error in your code: <DOCTYPE html> shouldn't that be <!DOCTYPE html>
- I used <br/> instead of <br> because you have a meta tag using it as well, but probably both are unnecessary.

Author Comment

ID: 40320563
Robert, very many thanks !!

Works perfectly.

Would you have a pointer to an online resource which deals with formatting topic ?

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.


Author Closing Comment

ID: 40320564
Just Great !!!!
LVL 35

Expert Comment

by:Robert Schutt
ID: 40320584
Well the documentation is kind of complex but there are ample examples:

Author Comment

ID: 40320609
thanks very much again !

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Keep Ditto Clipboard Manager open for multiple pastes 6 89
python - user input - set 4 81
Global Cyber attack 5 59
Looking for Lotus Organizer 6.1 software 7 25
Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
If your app took Google’s lash recently, here are the 5 most likely reasons.
The viewer will learn how to set up a document for the web and print and the recommended PPI for printing.
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question