Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63739
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-01-11 17:28 -0800 |
| Message-ID | <ccb82f25-c007-4e90-97d9-5108463ed51f@googlegroups.com> (permalink) |
| Subject | Is it better to import python modules inside function or at the top? What are the pros and cons? |
| From | Sam <lightaiyee@gmail.com> |
I have python modules which are used only in specific functions and the functions are not called all the time. Is it better to import the function inside the function only or is it a better practice to always import all modules at the top of the script? If I import the module inside the function, will it cause a big performance hit because of the import module action that gets to be called every time the function is called? What are the pros and cons of each approach?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Is it better to import python modules inside function or at the top? What are the pros and cons? Sam <lightaiyee@gmail.com> - 2014-01-11 17:28 -0800 Re: Is it better to import python modules inside function or at the top? What are the pros and cons? Chris Angelico <rosuav@gmail.com> - 2014-01-12 12:48 +1100 Re: Is it better to import python modules inside function or at the top? What are the pros and cons? Ned Batchelder <ned@nedbatchelder.com> - 2014-01-11 20:49 -0500
csiph-web