Re: Where to place imports

2009-01-23 Thread Steven D'Aprano
On Fri, 23 Jan 2009 17:48:19 +0100, Diez B. Roggisch wrote: > The only valid reason for doing imports inside functions is if you > otherwise get into circular dependency hell, or have modules that need > some manipulation of the sys.path before they actually can be imported. Or if you want to mak

Re: Where to place imports

2009-01-23 Thread Jean-Paul Calderone
On Fri, 23 Jan 2009 22:49:34 +0100, Christian Heimes wrote: Jean-Paul Calderone schrieb: BTW, if you ever find you are starting to write multi-threaded applications then you'll really regret it if you reuse code which does imports from inside functions. If two or more threads try to import a mo

Re: Where to place imports

2009-01-23 Thread Christian Heimes
Jean-Paul Calderone schrieb: >> BTW, if you ever find you are starting to write multi-threaded >> applications >> then you'll really regret it if you reuse code which does imports from >> inside functions. If two or more threads try to import a module >> simultaneously then one of them might find i

Re: Where to place imports

2009-01-23 Thread Jean-Paul Calderone
On 23 Jan 2009 18:50:00 GMT, Duncan Booth wrote: [snip] BTW, if you ever find you are starting to write multi-threaded applications then you'll really regret it if you reuse code which does imports from inside functions. If two or more threads try to import a module simultaneously then one of t

Re: Where to place imports

2009-01-23 Thread Duncan Booth
"John [H2O]" wrote: > So it isn't inefficient to import a bunch of modules that may not be > used, say if only one function is used that doesn't rely on a larger > module like numpy or pylab? > Not really. If you import it at all then you might as well import it on startup i.e. at the top of th

Re: Where to place imports

2009-01-23 Thread Diez B. Roggisch
Steve Holden schrieb: Diez B. Roggisch wrote: [...] The only valid reason for doing imports inside functions is if you otherwise get into circular dependency hell, or have modules that need some manipulation of the sys.path before they actually can be imported. This is never true for system modu

Re: Where to place imports

2009-01-23 Thread Steve Holden
Diez B. Roggisch wrote: [...] > The only valid reason for doing imports inside functions is if you > otherwise get into circular dependency hell, or have modules that need > some manipulation of the sys.path before they actually can be imported. > This is never true for system modules, and certainl

Re: Where to place imports

2009-01-23 Thread Diez B. Roggisch
John [H2O] schrieb: So it isn't inefficient to import a bunch of modules that may not be used, say if only one function is used that doesn't rely on a larger module like numpy or pylab? Well, importing can take bit of time - but that's a short latency at startup-time, if anything. And if you

Re: Where to place imports

2009-01-23 Thread John [H2O]
y been imported before. > > > The only valid reason for doing imports inside functions is if you > otherwise get into circular dependency hell, or have modules that need > some manipulation of the sys.path before they actually can be imported. > This is never true for system modules

Re: Where to place imports

2009-01-23 Thread Diez B. Roggisch
John [H2O] schrieb: Hello, Im writing some modules and I am a little confused about where to place my imports... I don't really do any class programming yet, just defining a bunch of functions, so presently I have something along the lines of: import sys import os import traceback def Foo1(a,

Where to place imports

2009-01-23 Thread John [H2O]
e? Or individually import them into functions. Is there a performance penalty either way? Pointers to a good reference are appreciated... -- View this message in context: http://www.nabble.com/Where-to-place-imports-tp21627895p21627895.html Sent from the Python - python-list mailing list archi