Re: Importing again and again

2006-06-09 Thread Maric Michaud
Le Jeudi 08 Juin 2006 22:02, abcd a écrit : > > def foo(): > import bar > bar.printStuff() > > foo() > foo() > foo() > foo() > > ...will that re-import bar 4 times...or just import it once? is this a > big performance hit? Import a module more than once doesn't execute the code of this mo

Re: Importing again and again

2006-06-09 Thread Steve Holden
abcd wrote: > If I have code which imports a module over and over again...say each > time a function is called, does that cause Python to actually re-import > it...or will it skip it once the module has been imported?? > > for example: > > def foo(): > import bar > bar.printStuff() > > f

Re: Importing again and again

2006-06-08 Thread Schüle Daniel
it's import-ed only once # magic.py file #!/usr/bin/python print "here" import magic# try to import itself then try # bad_magic.py #!/usr/bin/python print "here" import bad_magic reload(bad_magic) hth, Daniel -- http://mail.python.org/mailman/listinfo/python-list

Re: Importing again and again

2006-06-08 Thread John Bokma
"Terry Reedy" <[EMAIL PROTECTED]> wrote: > > "John Bokma" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >>> def foo(): >>> import bar >>> bar.printStuff() >> I am new to Python so this might be a weird question, but it there a >> reason why you import bar inside foo? > >

Re: Importing again and again

2006-06-08 Thread Terry Reedy
"John Bokma" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> def foo(): >> import bar >> bar.printStuff() > I am new to Python so this might be a weird question, but it there a > reason why you import bar inside foo? Two possible reasons: 1) delay import until actually nee

Re: Importing again and again

2006-06-08 Thread John Bokma
"abcd" <[EMAIL PROTECTED]> wrote: > If I have code which imports a module over and over again...say each > time a function is called, does that cause Python to actually re-import > it...or will it skip it once the module has been imported?? > > for example: > > def foo(): > import bar >

Re: Importing again and again

2006-06-08 Thread Laszlo Nagy
abcd írta: > If I have code which imports a module over and over again...say each > time a function is called, does that cause Python to actually re-import > it...or will it skip it once the module has been imported?? > > for example: > > def foo(): > import bar > bar.printStuff() > > foo()

Re: Importing again and again

2006-06-08 Thread John Salerno
abcd wrote: > def foo(): > import bar > bar.printStuff() > > foo() > foo() > foo() > foo() > > ...will that re-import bar 4 times...or just import it once? is this a > big performance hit? > > thanks > Given a file called bar.py with the following contents: print "I'm being imported

Re: Importing again and again

2006-06-08 Thread Dustan
abcd wrote: > If I have code which imports a module over and over again...say each > time a function is called, does that cause Python to actually re-import > it...or will it skip it once the module has been imported?? > > for example: > > def foo(): > import bar > bar.printStuff() > > foo