On Wednesday, February 16, 2011 8:38:40 AM UTC, galago wrote: > > Is it a good idea to import modules in the middle of the code, and not on > the beginning? > I want to make a hash generation. It's few lines - it's used once in all > application. Should I import hashlib just on the beginning of the file? Now > I put it with the rest of the code. > Is it bad? > > I don't want to import it with all requests in my app view. >
Your question betrays a misconception that I often see. Django - at least when served other than via CGI - does not reload everything for each request. The Django process is long-running, and is managed by the server, but usually runs for a number of requests before being respawned. So given that once you've imported something it stays available for the lifetime of the process, it makes very little difference where you do it. IMO the only reason not to import modules at the top of the file is to avoid circular dependencies. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.