Is "python -W ignore" the default?

R

rihad

$ mkdir foo
$ python
Python 2.7 (r27:82500, Sep 1 2010, 22:10:47)
[GCC 4.2.1 20070719 [FreeBSD]] on freebsd7
Type "help", "copyright", "credits" or "license" for more information.
dir() ['__builtins__', '__doc__', '__name__', '__package__']
import foo
Traceback (most recent call last):
['__builtins__', '__doc__', '__name__', '__package__',
'__warningregistry__'][(("Not importing directory 'foo': missing __init__.py", <type
'exceptions.ImportWarning'>, 1), True)]$ (...went to read some "man python"...)
$ python -W default
Python 2.7 (r27:82500, Sep 1 2010, 22:10:47)
[GCC 4.2.1 20070719 [FreeBSD]] on freebsd7
Type "help", "copyright", "credits" or "license" for more information.__main__:1: ImportWarning: Not importing directory 'foo': missing
__init__.py
Traceback (most recent call last):
$

The problem isn't easily spotted unless run with -W default. How come
"default" is not on by default? :)
 
D

Dennis Lee Bieber

The problem isn't easily spotted unless run with -W default. How come
"default" is not on by default? :)

Seems to me that the root problem is easily discovered... The
original error says "no module named ...", so what does one find when
checking the directory system for that "module"...

In your case, you find a /directory/ instead a .py file...

Directories are only importable modules if they are configured as a
package; packages are defined by having an __init__.py file.

The extra warnings are just noise to me... They explain why
/directory/ "xxx" was not imported, but maybe the directory isn't
supposed to be an importable package! Maybe you really ARE missing a
xxx.py file and the xxx directory was tried just because it was later in
the search path.
 
D

Dennis Lee Bieber

Seems to me that the root problem is easily discovered... The
original error says "no module named ...", so what does one find when
checking the directory system for that "module"...

In your case, you find a /directory/ instead a .py file...

Follow-up (something I thought was less... aggressive... while at
work).

"import foo"

looks for any of (I'm not going to look up the search order):

foo.py (python source file)
foo.pyc or foo.pyo (byte code compiled file, depending on optimization
option)
foo.pyd ([C] extension module; DLL/SO depending on OS)
foo/__init__.py ("package" directory).

Knowing that a "foo" directory was found which did not contain an
__init__.py file is meaningless when the real problem could be that one
has a Foo.py that should have been named foo.py... (maybe the foo
directory is meant to hold configuration data files, but not the module
itself!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top