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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:33:33+00:00 2026-05-15T01:33:33+00:00

After just been coding for about 6-9 months. I probably changed my coding style

  • 0

After just been coding for about 6-9 months. I probably changed my coding style a number of times after reading some code or read best practices. But one thing I haven’t yet come a cross is a good why to populate the template_dict.

As of now I pass the template_dict across a number of methods (that changes/modifies it) and returns is. The result is that every methods takes template_dict as first argument and the returns it and this in my eyes doesn’t seems to be the best solution.

An idea is to have a method that handles all the changes. But I’m curios if there’s a best practice for this? Or is it “do what you feel like”-type of thing?

The 2 things I think is pretty ugly is to send as an argument and return it in all methods. And the just the var name is written xxx number of times in the code 🙂

..fredrik

EDIT:

To demonstrate what I mean with template_dict (I thought that was a general term, I got it from the google implementation of django’s template methods).

I have an dict I pass to the template via the render.template method:

template.render(path, template_dict) #from google.appengine.ext.webapp import template

This template_dict I need to manipulate in order to send data/dicts/lists to the view (html-file). If I’m not mistaken.

So with this in mind, my code usually ends up looking some this like this:

## Main.py file to handle the request and imports classes.

from models import data
from util import foo

class MainHandler(webapp.RequestHandler):
    template_dict = { 'lang' : 'en' }
    ## reads all current keys and returns dict w/ new keys, if needed
    template_dict = data.getData(template_dict) 
    if 'unsorted_list' in template_dict:
        template_dict = util.foo(template_dict)
    ## and so on....

    path = os.path.join(os.path.dirname(__file__), 'templates', file)
    self.response.out.write(template.render(path, template_dict))

In most of my applications the many returns and sets doesn’t appear in the main.py but rather in other classes and methods.

But you should do the general idea.

  • 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-15T01:33:34+00:00Added an answer on May 15, 2026 at 1:33 am

    If the functions in question are all methods of some object foo, then each of them can refer to the context they’re building up (I imagine that’s what you mean by “template dict”?) as self.ctx or the like (attribute name’s somewhat arbitrary, the key point is that you can keep the context as an attribute of foo, typically initialized to empty in foo‘s __init__, and incrementally build it up via foo‘s methods; in the end, foo.ctx is ready for you).

    This doesn’t work in a more general case where the functions are all over the place rather than being methods of a single object. In that case ctx does need to be passed to each function (though the function can typically alter it in-place and doesn’t need to return it).

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

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • 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're sorting at the wrong level. If you want to… May 15, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer To find them anywhere in the document, use xdoc.Descendants("ARTICLE") to… May 15, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer CGImageGetBitsPerComponent( image ); CGImageGetBitsPerPixel( image ); CGImageGetBytesPerRow( image ); CGImageGetBitmapInfo(… May 15, 2026 at 3:20 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

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.