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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:01:46+00:00 2026-05-16T08:01:46+00:00

I am new to Python – be forewarned! I have a template class that

  • 0

I am new to Python – be forewarned!

I have a template class that takes a list as an argument and applies the members of the list to the template. Here’s the first class:

class ListTemplate:

    def __init__(self, input_list=[]):
        self.input_list = input_list

    def __str__(self):
        return "\n".join([self._template % x for x in self.input_list])

Here’s the template code/class:

class HTML_Template(ListTemplate):

    _template = """ 
      <li>
        <table width="100%%" border="0">
          <tr>
            <td>Title: %(title)s</td>
            <td>Link: %(isbn)s</td>
          </tr>
          <tr>
            <td>Author: %(author)s</td>
            <td>Date: %(pub_date)s</td>
          </tr>
          <tr>
            <td>Summary: %(isbn)s</td>
            <td>Description: %(descr)s</td>
          </tr>
        </table>
        <hr>
      </li>"""

Here’s the problem:

I’m pulling data from a sqlite database using fetchall, which return a list of tuples. I can pass this list of tuples to this method fine by changing the template to %s instead of %(isbn) …etc., however, I need to access the isbn member multiple times in the template. To do this now, I load the tuples in to dictionaries and push them into another list …then pass the list of dictionaries. This strikes me as inefficient. My question is: how would you rewrite this so that the original list of tuples could be passed to the template (thus, saving a step ), while still allowing access to the individual members by ie., item[0] or similar?

Thanks ~

Bubnoff

  • 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-05-16T08:01:46+00:00Added an answer on May 16, 2026 at 8:01 am

    If you use the new string formatting, it may be possible to operate solely on indices…

    But that will be horrible to decipher, even with the database scheme at hand. The list-of-dict approach sounds much saner, and unless you operate a really frequently-visited service, the performance impact won’t be too bad (this depends on the size of the data set – but you don’t get 3k 7-tuples at once, do you?). Dictionaries are rather efficient in Python. Caching could also help performance-wise.

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

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you can't have your view paint over what's already in… May 16, 2026 at 3:53 pm
  • Editorial Team
    Editorial Team added an answer Finally... No ping requried at all... http://www.codeproject.com/KB/cs/c__ip_scanner.aspx All I needed… May 16, 2026 at 3:53 pm
  • Editorial Team
    Editorial Team added an answer The error message you give is to general to help.… May 16, 2026 at 3:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm new to Python and I have been trying to search through html with
I'm new Python and trying to implement code in a more Pythonic and efficient
I'm a new Python programmer who is making the leap from 2.6.4 to 3.1.1.
I'm a new Python programmer who is having a little trouble using 'self' in
I'm a very new python user (had only a little prior experience with html/javascript
I'm starting a new Python web project. With most frameworks, everyone rushes to the
http://docs.python.org/3.0/whatsnew/3.0.html says it lists whats new , but in my opinion, it only lists
I want to install the new Python 2.7 on my Windows XP 32bit PC.
Suppose a programmer has the following problem: he wants to start a new python
I'm new to python and django, and when following the Django Book I learned

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.