Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:57:34+00:00 2026-06-02T00:57:34+00:00

I have the following code that generates the desired HTML. But it prints it

  • 0

I have the following code that generates the desired HTML. But it prints it at the top of the page, instead of where I want it.

def fixText(self,text):
    row = []
    z = text.find(',')

    if z == 0: row.append('')
    else:      row.append(text[:z])

    for x in range(len(text)):
        if text[x] != ',': pass
        else:
            if x == (len(text)-1): row.append('')
            else:
                if ',' in text[(x+1):]:
                    y = text.find(',', (x+1))
                    c = text[(x+1):y]
                else:
                    c = text[(x+1):]
                    row.append(c)
    return row

def output(self):
    output = ""
    fob=open('files/contacts.txt','r')
    tup = []

    while 1:
        text = fob.readline()

        if text == "": break
        else: pass

        if text[-1] == '\n':
            text = text[:-1]
        else: pass

        row = self.fixText(text)
        tup.append(row)

    output = tup.sort(key=lambda x: x[0].lower())

    _list1 = len(tup)
    i = 0
    table = ""

    while i < _list1:
        j = 0 #need to reset j on each iteration of i
        _list2 = len(tup[i])
        print("<tr>")

        while j < _list2:
            print("<td>" + tup[i][j] + "</td>")
            j += 1

        print("</tr>")
        i += 1

    return output

As you can see, I have a nested loop that prints out the HTML code. This works fine, but when I try to inject it into my modular site it prints it at the top of the page. My hunch is that the following code is the part I need to change.

#!/usr/local/bin/python3

print('Content-type: text/html\n')

import os, sys
import cgitb; cgitb.enable()

sys.path.append("classes")

from Pagedata import Pagedata
Page = Pagedata()

print(Page.doctype())
print(Page.head())
print(Page.title("View Contact"))
print(Page.css())

html='''</head>
<body>
<div id="wrapper">
    <div id="header">
        <div id="textcontainer">{1}</div>
    </div>
    <div id="nav">{2}</div>
    <div id="content">
        <h2>Heading</h2>
        <h3>Sub Heading Page 2</h3>
        <table>
            <tbody>
                {0}
            </tbody>
        </table>    
    </div>
<div>
<div id="footer">{3}</div>
</body>
</html>'''.format(Page.output(),Page.header(),Page.nav(),Page.footer())

print(html)

There are other functions on my class page, such as header, footer, etc., that work fine.

For example, the footer is properly inserted into div#footer. But the generated table si not inserted where {0} is.

You can view the broken code here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:57:35+00:00Added an answer on June 2, 2026 at 12:57 am

    You shouldn’t use print inside def output(self): because that it s printing directly during the look on sys.stdout

    table = ""
    while i < _list1:
        j = 0#need to reset j on each iteration of i
        _list2 = len(tup[i])
        table += "<tr>"
        while j < _list2:
            table=+"<td>" + tup[i][j] + "</td>"
            j += 1
        table += "</tr>"
        i += 1
    return table
    

    You html variable should be populated properly before you print without any print on stdout

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that generates my form on my html page <input
I have the following SVG source code that generates a number of boxes with
I have the following code that generates a compiler error: Boolean IConvertible.ToBoolean(IFormatProvider provider) {
I have the following python code that generates a list of anonymous functions: basis
I have the following code that correctly generates the CKEditor: <script> $(function(){ $(#newWrite_body).ckeditor({ extraPlugins
I have following code that does not work due to a being a value
I have following code that does not work: I never get to goToFoodDetail .
I have following code snippet that i use to compile class at the run
I have the following code that shows either a bug or a misunderstanding on
I have the following code that won't compile and although there is a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.