Basic import Questions (with bonus profiling question)
Fredrik Lundh
fredrik at pythonware.com
Thu Aug 31 12:38:30 EDT 2006
Gregory Piñero wrote:
> 1. Will "from somemodule import onething" take as long to start up as
> import somemodule?
yes; "from x import y" does an ordinary import of "x" under the hood.
> 2. Is there anyway I can get at onething more quickly?
not really, unless you're willing/able to refactor the module you're
importing.
> 3. If I put an import statement hidden away in some function, will
> Python only do the import when that function is called?
correct. "import" is an executable statement.
> If I say, never use that function would that import statement affect
> performance at all?
nope.
> Ultimately I have IIS running python as a CGI script and it seems to
> just be taking many seconds to load a small page. I'm guessing the
> issue is starting up the interpreter and loading all the modules.
several seconds? sounds bad. what does the following script print on
your machine?
import time, subprocess, sys
t0 = time.time()
for i in range(10):
subprocess.call([sys.executable, "-c", "pass"])
print time.time() - t0
</F>
More information about the Python-list
mailing list