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 8809901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:59:28+00:00 2026-06-14T02:59:28+00:00

Input:- CRlist [[‘CR’, ‘FA’, ‘CL’, ‘TITLE’], [‘409452’, ‘WLAN’, ‘656885’, ‘Age out RSSI values from

  • 0

Input:-

   CRlist
  [['CR', 'FA', 'CL', 'TITLE'], ['409452', 'WLAN', '656885', 'Age out RSSI values from buffer in Beacon miss scenario'], ['379104', 'BT', '656928', 'CR379104: BT doesn\xe2\x80\x99t work that Riva neither sends HCI Evt for HID ACL data nor response to HCI_INQUIRY after entering into pseudo sniff subrating mode.']]

I have the following pythong code to generate HTML code but its generating an output which am not expecting,I pring the array values before which seem to have right data here but while using.format something is getting messedup..can anyone point what is wrong here?

for i in range(len(CRlist)):
    if i==0:
        continue
    for j in range(len(CRlist[0])):
        print "i"
        print i
        print "j"
        print j
        print "CRlist[i][j]"
        print CRlist[i][j]//right data here
        CRstring += """
        <tr>
        <td><a href="{CR}">{CR}</a></td>
        <td>{FA}</td>
        <td>{CL}</td>
        <td>{Title}</td>
        </tr>""".format(
            CR=CRlist[i][j],
            FA=CRlist[i][j],
            CL=CRlist[i][j],
            Title=CRlist[i][j],
            )
CRstring += "\n</table>\n"

My expectation of output but is getting created incorrectly

   <tr>
   <td><a href="409452">409452</a></td>
   <td>WLAN</td>
   <td>656885</td>
   <td>Age out RSSI values from buffer in Beacon miss scenario</td>
   </tr>
    ..............

Actual output,as you can the row cell data is redundant

                   <tr>
                   <td><a href="409452">409452</a></td>
                   <td>409452</td>
                   <td>409452</td>
                   <td>409452</td>
                   </tr>
                   <tr>
                   <td><a href="WLAN">WLAN</a></td>
                   <td>WLAN</td>
                   <td>WLAN</td>
                   <td>WLAN</td>
                   </tr>
                   <tr>
                   <td><a href="656885">656885</a></td>
                   <td>656885</td>
                   <td>656885</td>
                   <td>656885</td>
                   </tr>
                   <tr>
                   <td><a href="Age out RSSI values from buffer in Beacon miss scenario">Age out RSSI values from buffer in Beacon miss scenario</a></td>
                   <td>Age out RSSI values from buffer in Beacon miss scenario</td>
                   <td>Age out RSSI values from buffer in Beacon miss scenario</td>
                   <td>Age out RSSI values from buffer in Beacon miss scenario</td>
                   </tr>
                   <tr>
                   <td><a href="379104">379104</a></td>
                   <td>379104</td>
                   <td>379104</td>
                   <td>379104</td>
                   </tr>
                   <tr>
                   <td><a href="BT">BT</a></td>
                   <td>BT</td>
                   <td>BT</td>
                   <td>BT</td>
                   </tr>
                   <tr>
                   <td><a href="656928">656928</a></td>
                   <td>656928</td>
                   <td>656928</td>
                   <td>656928</td>
                   </tr>
                   <tr>
                   <td><a href="CR379104: BT doesnΓÇÖt work that Riva neither sends HCI Evt for HID ACL data nor response to HCI_INQUIRY after entering into pseudo sniff subrating mode.">CR379104: BT doesnΓÇÖt work that Riva neither sends HCI Evt for HID ACL data nor response to HCI_INQUIRY after entering into pseudo sniff subrating mode.</a></td>
                   <td>CR379104: BT doesnΓÇÖt work that Riva neither sends HCI Evt for HID ACL data nor response to HCI_INQUIRY after entering into pseudo sniff subrating mode.</td>
                   <td>CR379104: BT doesnΓÇÖt work that Riva neither sends HCI Evt for HID ACL data nor response to HCI_INQUIRY after entering into pseudo sniff subrating mode.</td>
                   <td>CR379104: BT doesnΓÇÖt work that Riva neither sends HCI Evt for HID ACL data nor response to HCI_INQUIRY after entering into pseudo sniff subrating mode.</td>
                   </tr>
/table>

=========PLlist==========

  • 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-14T02:59:29+00:00Added an answer on June 14, 2026 at 2:59 am

    This code supplies the same value to each template variable:

    CR=CRlist[i][j],
    FA=CRlist[i][j],
    CL=CRlist[i][j],
    Title=CRlist[i][j],
    

    Obviously, that does not work as you intended. Here’s another way of writing it:

    TEMPLATE = """
        <tr>
        <td><a href="{CR}">{CR}</a></td>
        <td>{FA}</td>
        <td>{CL}</td>
        <td>{Title}</td>
        </tr>
    """
    
    for i, item in enumerate(CRlist):
        if i == 0:
            continue
    
        CRstring += TEMPLATE.format(
            CR=item[0],
            FA=item[1],
            CL=item[2],
            Title=item[3],
        )
    
    CRstring += "\n</table>\n"
    

    You could even remove the i and enumerate bits by slicing the list:

    for item in CRList[1:]:
        CRstring += # ...
    

    Since you’re generating HTML and are using user input (I assume, at least) and aren’t escaping the HTML, you’ve got an XSS vulnerability. Let’s fix that, too:

    # near the top of the file:
    import cgi
    
    # later...
    # ...
    CRstring += TEMPLATE.format(
        CR=cgi.escape(item[0]),
        FA=cgi.escape(item[1]),
        # ...
    )
    

    Further improvements

    That’s all well and fine, but as someone pointed out in the comments, you may be better off using a real template engine. I like Jinja2, personally. Here’s how you’d do that:

        {%- for item in cr_list[1:] %}
            <tr>
                <td><a href="{{ item[0] | escape }}">{{ item[0] | escape }}</a></td>
                <td>{{ item[1] | escape }}</td>
                <td>{{ item[2] | escape }}</td>
                <td>{{ item[3] | escape }}</td>
            </tr>
        {%- endfor %}
    </table>
    

    Furthermore, you may want to put your data into objects. For example:

    class CREntry(object):
        def __init__(self, cr, fa, cl, title):
            self.cr = cr
            self.fa = fa
            self.cl = cl
            self.title = title
    

    Then you can convert it quite simply:

    entries = [CREntry(*entry) for entry in CRlist[1:]]
    

    Then your code becomes much more clear, being able to reference entry.title rather than item[3].

    You may also want to use the normal Python conventions as outlined in PEP 8.

    If you’ve got that done, your code looks like this:

    import jinja2
    
    env = jinja2.Environment(autoescape=True)  # no more | escape everywhere!
    
    template = env.from_string(r"""
            {%- for entry in entries %}
                <tr>
                    <td><a href="{{ entry.cr }}">{{ entry.cr }}</a></td>
                    <td>{{ entry.fa }}</td>
                    <td>{{ entry.cl }}</td>
                    <td>{{ entry.title }}</td>
                </tr>
            {%- endfor %}
        </table>
    """)
    
    class CREntry(object):
        # ...
    
    # later...
    entries = [CREntry(*entry) for entry in cr_list]
    cr_string = template.render(entries=entries)
    

    A little more code elsewhere, but less when you’re actually generating the HTML, and I’d say it’s much more maintainable.

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

Sidebar

Related Questions

input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;} input,textarea,select{*font-size:100%;} This is from the YUI reset css. What does the * before
Input: a maze represented by an arbitrarily sized matrix of bools. (Out of bounds
Input: I want to remove double space from textbox. Output: I want to remove
Input : a,b,c,d,e q,w,34,r,e 1,2,3,4,e In mapper, I would grab all the values of
Input: List of keys: [ :name :address :work] Map 1: { :name A :address
Input @StartDate = '01/25/2010' @EndDate = '02/06/2010' I have 2 CTEs in a stored
Input : {5, 13, 6, 5, 13, 7, 8, 6, 5} Output : {5,
Input: SHC 111U,SHB 22x,, SHA 5555G Needed output: SHB 22X, SHC 111U, SHA 5555G
Input: I have a LaTeX file, with plain text & math formulas. Desired output:
Input rz value In the head I have: Event.observe(window, 'load', function() { $$(input).each(function(field){ Event.observe(field,

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.