According to the Python Coding Guidelines you should always put the imports at the top of a file simply because it makes the file more readable. Performance-wise there are AFAIK some small speed-ramifications (negative ones) when putting imports into a function instead of having them at the module level. My guess would be, that this has something to do with the compile-time vs. runtime issue, not to mention that the import-statement isn't really free. On the other hand memory usage should be lower if you only import something if it's really needed (say: inside of a view-function). I haven't really run any benchmarks, though.
You might want to take a look at http://www.szgti.bmf.hu/harp/python/fastpython.html :-) - Horst On Mon, Oct 27, 2008 at 3:06 PM, 7timesTom <[EMAIL PROTECTED]> wrote: > I have a large number of view functions which require various python, > django and other import statements. > > My question is: is it ok to put ALL my import statements at the top of > views.py and then not have to worry about which view fuction uses > what. Or must I put my imports within the view fuctions that require > them? > > Does it depend on how many functions require I certain import? And if > so, how many imports justifies a global import at the top of the code? > > I'm interested on the effect this decision has on speed/memory usage > etc. > > > --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---