Re: Question about using imports within functions/methods

2011-06-02 Thread Cal Leeming [Simplicity Media Ltd]
On Thu, Jun 2, 2011 at 4:46 PM, Shawn Milochik wrote: > On 06/02/2011 11:09 AM, Cal Leeming [Simplicity Media Ltd] wrote: > >> >> Pretty shameful that after almost 6 years of (fairly advanced) Python >> coding, I still finding myself not knowing some of the basic 101 stuff.. >> Slightly off topic

Re: Question about using imports within functions/methods

2011-06-02 Thread Shawn Milochik
On 06/02/2011 11:09 AM, Cal Leeming [Simplicity Media Ltd] wrote: Pretty shameful that after almost 6 years of (fairly advanced) Python coding, I still finding myself not knowing some of the basic 101 stuff.. Slightly off topic but, does anyone else have that issue when coding? (i.e. doing re

Re: Question about using imports within functions/methods

2011-06-02 Thread Cal Leeming [Simplicity Media Ltd]
Thanks to Tom / Matias / Brian for taking the time to reply, and for providing some good links, this was *exactly* what I needed. In regards to circular import issues, this is pretty much the main reason I've put imports inside function/method before, and I agree that most of the time it can be re

Re: Question about using imports within functions/methods

2011-06-02 Thread Matías Aguirre
Imports are cached by python that way things get imported only the first time. Try this simple test, create a file a.py with this content: print "Importing a.py" Then create b.py with this other content: import a Then create c.py with this other content: def x(): import a

Re: Question about using imports within functions/methods

2011-06-02 Thread Tom Evans
On Thu, Jun 2, 2011 at 3:39 PM, Cal Leeming [Simplicity Media Ltd] wrote: > Hey guys, > > This is more of a python question, than a Django specific one, but it's been > bugging me for years now lol. > > I'm trying to figure out if it is better to do imports at the top of the > file, or within the

Re: Question about using imports within functions/methods

2011-06-02 Thread Brian Bouterse
Yes relative imports are explicitly discouraged in PEP 8. Look for the imports section. I do not recommend importing at runtime which is what you are doing when you put imports inside function/methods. There are performance problems when calling imports