Re: where to import

2011-02-17 Thread Santoso Wijaya
As a general rule, I group all my imports in the beginning of the module's source, even if it is only used a handful of times by a few functions. However, on such cases as the import is only needed by specific function(s) zero or once, then I do the import in the function itself. Importing argpars

Re: where to import

2011-02-17 Thread Terry Reedy
On 2/17/2011 12:27 PM, andrea crotti wrote: Well no I wasn't really worried about performances. I just thought that if an external module is really almost never used, it might make sense to import it only when it's really needed. If the module is only used in one function and the function may

Re: where to import

2011-02-17 Thread andrea crotti
2011/2/17 Chris Rebert > Yes, of course. Importing a module multiple times (as would happen if > fun() is called multiple times) is obviously slower than just > importing it once, although the 2nd and subsequent imports will be > faster as Python will just return another reference to the previous

Re: where to import

2011-02-17 Thread Chris Rebert
On Thu, Feb 17, 2011 at 8:44 AM, andrea crotti wrote: > Suppose I have a function which uses a few external libraries, > and this function is only called once every 10 executions. > > Does it make sense to import these libraries for the whole module? Yes. Having all the imports in one place keeps

where to import

2011-02-17 Thread andrea crotti
Suppose I have a function which uses a few external libraries, and this function is only called once every 10 executions. Does it make sense to import these libraries for the whole module? import sys def fun(): import x, y, z Something like this is acceptable/good practice in the scenario I

TitleCase, camelCase, lowercase (was: Where to "import"?)

2007-03-08 Thread Ben Finney
"Gabriel Genellina" <[EMAIL PROTECTED]> writes: > Class names should be CamelCase. Note that the term "camel case" has ambiguous usage. Some use it to refer to *both* of "nameWithSeveralWords" and "NameWithSeveralWords". I prefer to use the term "title case" to refer unambiguously to "NameWithSe

Re: Where to "import"?

2007-03-08 Thread MonkeeSage
On Mar 8, 10:27 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > Class names should be CamelCase. Read it again, and notice the difference > between a "Descriptive" section and a "Prescriptive" one. Yes, I misread Bruno's comment (missed that he was speaking of class names). Disregard my post.

Re: Where to "import"?

2007-03-08 Thread Gabriel Genellina
En Fri, 09 Mar 2007 01:09:36 -0300, MonkeeSage <[EMAIL PROTECTED]> escribió: >> FWIW:http://www.python.org/dev/peps/pep-0008/ > > By my reading, PEP8 doesn't specify CamelCase as preferred over the > other styles it mentions. non_camel_case is also considered good > style, as I understand (and i

Re: Where to "import"?

2007-03-08 Thread MonkeeSage
Disregard my last message, I'm stupid. I totally missed that Bruno was talking about classname. Bruno is exactly right. -- http://mail.python.org/mailman/listinfo/python-list

Re: Where to "import"?

2007-03-08 Thread MonkeeSage
On Mar 8, 5:49 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> > >>1/ better to stick to naming conventions (class names in CamelCase) > > > Ok. Thanks. > > FWIW:http://www.python.org/dev/peps/pep-0008/ By my reading, PEP8 doesn't specify CamelCase as preferred over the other styles it mentions. non_c

Re: Where to "import"?

2007-03-08 Thread Bruno Desthuilliers
Paulo da Silva a écrit : > Bruno Desthuilliers escreveu: > >>Paulo da Silva a écrit : > > ... > > >>>c.py >>>class c: >> >>class C(object): >> >>1/ better to stick to naming conventions (class names in CamelCase) > > Ok. Thanks. FWIW: http://www.python.org/dev/peps/pep-0008/ >>2/

Re: Where to "import"?

2007-03-08 Thread Paulo da Silva
Bruno Desthuilliers escreveu: > Paulo da Silva a écrit : ... >> >> c.py >> class c: > class C(object): > > 1/ better to stick to naming conventions (class names in CamelCase) Ok. Thanks. > 2/ do yourself a favor: use new-style classes I still have python 2.4.3 (The gentoo current vers

Re: Where to "import"?

2007-03-08 Thread Paulo da Silva
Paulo da Silva escreveu: This is to thank all the answers I got so far. Now I understand perfectly how "import" works. Regards. Paulo -- http://mail.python.org/mailman/listinfo/python-list

Re: Where to "import"?

2007-03-08 Thread Paulo da Silva
Paulo da Silva escreveu: This is to thank all the answers I got so far. Now I understand perfectly how "import" works. Regards. Paulo -- http://mail.python.org/mailman/listinfo/python-list

Re: Where to "import"?

2007-03-08 Thread Ben Finney
Paulo da Silva <[EMAIL PROTECTED]> writes: > Hi! > > If I have two files .py such as > > m.py > from c import * Best done as either import c# then use 'x = c.c()' or from c import c Using 'from foo import *' leads to names appearing in your current namespace that are difficu

Re: Where to "import"?

2007-03-08 Thread Matimus
> both using os module where should I put the "import os"? In both files? You don't really have a choice, you have to import os in both files. Python will only load the os module into memory once, but the import statements are needed to add the os module to the c and m module namespaces. The code

Re: Where to "import"?

2007-03-08 Thread Bruno Desthuilliers
Paulo da Silva a écrit : > Hi! > > If I have two files .py such as > > m.py > from c import * avoid this kind of import except in an interactive interpreter and eventually in a package __init__.py. Better to use either: from c import c or import c ... x = c.c() > ... >

Re: Where to "import"?

2007-03-08 Thread Terry Reedy
"Paulo da Silva" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Hi! | | If I have two files .py such as | | m.py | from c import * | ... | x=c() | ... | os.any_method ... | ... | | c.py | class c: | def __init__(self, ...): | ... | os.any_method ... | ... | ... | | both using os mo

Where to "import"?

2007-03-08 Thread Paulo da Silva
Hi! If I have two files .py such as m.py from c import * ... x=c() ... os.any_method ... ... c.py class c: def __init__(self, ...): ... os.any_method ...