On Fri, 07 Aug 2009 16:50:12 +, kj wrote:
I seek the wisdom of the elders. Is there a consensus on the matter of
conditional imports? Are they righteous? Or are they the way of the
wicked?
Being an elder doesn't grant you wisdom. It just might mean you've been
stupid and ignorant for
Conditional imports make sense to me, as in the following example:
def foobar(filename):
if os.path.splitext(filename)[1] == '.gz':
import gzip
f = gzip.open(filename)
else:
f = file(filename)
# etc.
And yet, quoth PEP 8:
- Imports are always put at the
On Aug 8, 2:50 am, kj no.em...@please.post wrote:
Conditional imports make sense to me, as in the following example[...]
And yet, quoth PEP 8:
- Imports are always put at the top of the file, just after any module
comments and docstrings, and before module globals and constants.
On Fri, 2009-08-07 at 16:50 +, kj wrote:
Conditional imports make sense to me, as in the following example:
def foobar(filename):
if os.path.splitext(filename)[1] == '.gz':
import gzip
f = gzip.open(filename)
else:
f = file(filename)
# etc.
On Fri, 2009-08-07 at 16:50 +, kj wrote:
Conditional imports make sense to me, as in the following example:
def foobar(filename):
if os.path.splitext(filename)[1] == '.gz':
import gzip
f = gzip.open(filename)
else:
f = file(filename)
# etc.
I
kj wrote:
Conditional imports make sense to me, as in the following example:
def foobar(filename):
if os.path.splitext(filename)[1] == '.gz':
import gzip
f = gzip.open(filename)
else:
f = file(filename)
# etc.
And yet, quoth PEP 8:
- Imports
kj wrote:
I seek the wisdom of the elders. Is there a consensus on the matter
of conditional imports? Are they righteous? Or are they the way
of the wicked?
imports in functions are dangerous and may lead to dead locks if they
are mixed with threads. An import should never start a thread
Peter Otten __pete...@web.de wrote:
This criterion is unlikely to be met for the examples you give above. time
is a built-in module, and gzip a thin wrapper around zlib which is also
built-in.
This is something I was _utterly_ unaware of. Is there a list of what
modules are built-in readily
Albert Hopkins wrote:
On Fri, 2009-08-07 at 16:50 +, kj wrote:
Conditional imports make sense to me, as in the following example:
def foobar(filename):
if os.path.splitext(filename)[1] == '.gz':
import gzip
f = gzip.open(filename)
else:
f = file(filename)
alex23 wrote:
This is something I was _utterly_ unaware of. Is there a list of what
modules are built-in readily available?
sys.builtin_module_names
('__builtin__', '__main__', '_ast', '_bisect', '_codecs', '_collections',
'_functools', '_locale', '_random', '_socket', '_sre', '_struct',
10 matches
Mail list logo