Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36794
| References | <kd1667$k6$1@news1.carnet.hr> |
|---|---|
| Date | 2013-01-15 02:04 +1100 |
| Subject | Re: Python modules |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.502.1358175849.2939.python-list@python.org> (permalink) |
On Tue, Jan 15, 2013 at 1:54 AM, zoom <zoom@yahoo.com> wrote: > Is there any "rules" regarding importing python modules within your own > module? I mean, how does this affects the performance of the program? > > In short, when creating a module, is it worthwhile to be careful and import > only necessary functions, nothing more? Nope. When you import a module, a record of it is kept in sys.modules, so the next time you import it, it's just picking up the same module object. > scipy.r_[a] = sound.scipy.r_[a] They'll actually be the same thing, which you can test with the 'is' operator. The performance cost of reimporting a module is very low; in fact, trying to avoid it by adorning all your usage with an extra dot-level will probably cost you a lot more, since there'll be an extra lookup every time. Have at it! :) ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python modules zoom <zoom@yahoo.com> - 2013-01-14 15:54 +0100
Re: Python modules Dan Sommers <dan@tombstonezero.net> - 2013-01-14 15:01 +0000
Re: Python modules zoom <zoom@yahoo.com> - 2013-01-14 16:03 +0100
Re: Python modules Chris Angelico <rosuav@gmail.com> - 2013-01-15 02:04 +1100
Re: Python modules Rick Johnson <rantingrickjohnson@gmail.com> - 2013-01-14 08:27 -0800
Re: Python modules Rick Johnson <rantingrickjohnson@gmail.com> - 2013-01-14 08:27 -0800
Re: Python modules Grant Edwards <invalid@invalid.invalid> - 2013-01-14 19:48 +0000
csiph-web