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
  • 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 ?

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)


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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will learn common shortcuts with easy ways to remember them. The viewer will then learn where to find all of the keyboard shortcuts, how to create/change them, and how to speed up their workflow.
Viewers will learn how to use the Hootsuite Dashboard.

829 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