K
Kay Schluehr
1. I'd expected that absolute imports are used in Python 3.0 by
default. I may be wrong. I've written two versions of a module
sucks.py
sucks.py
-------------
print ("import from lib.sucks")
sucks.py
-------------
print ("import from package.sucks")
The first is placed in the lib directory that is globally visible by
means of PYTHONPATH. The second one is placed in a package
package/
__init__.py
sucks.py
A.py
The package also contains a module A.py defined by
A.py
------
import sucks
Running A yields "import from package.sucks" which means unconditional
relative import. It shadows the globally visible sucks.py module. I've
expected it the other way round.
2. This is kind of a change request.
In a former life I used to call test-scripts as test-scripts. The dumb
idea was to point e.g. to
lib/tests and run
python test_ast.py
test_nodeclasses (__main__.AST_Tests) ... ok
....
test_parse (__main__.ASTHelpers_Test) ... ok
----------------------------------------------------------------------
Ran 12 tests in 0.219s
OK
The new style is implemented rather in lib2to3. If I point to lib/
lib2to3/tests and run
python test_parser.py
Traceback (most recent call last):
File "test_parser.py", line 12, in <module>
from . import support
ValueError: Attempted relative import in non-package
The standard error of the years to come that makes working with Python
harder and reminds me that it is not a scripting language anymore
because you can't run anything as a script not even a test.
For pedagogical reasons the behavior of test_ast.py and other standard
library tests shall show uniform behavior when called from the command
line i.e. they shall all fail with this import error message. What do
you think?
default. I may be wrong. I've written two versions of a module
sucks.py
sucks.py
-------------
print ("import from lib.sucks")
sucks.py
-------------
print ("import from package.sucks")
The first is placed in the lib directory that is globally visible by
means of PYTHONPATH. The second one is placed in a package
package/
__init__.py
sucks.py
A.py
The package also contains a module A.py defined by
A.py
------
import sucks
Running A yields "import from package.sucks" which means unconditional
relative import. It shadows the globally visible sucks.py module. I've
expected it the other way round.
2. This is kind of a change request.
In a former life I used to call test-scripts as test-scripts. The dumb
idea was to point e.g. to
lib/tests and run
python test_ast.py
test_nodeclasses (__main__.AST_Tests) ... ok
....
test_parse (__main__.ASTHelpers_Test) ... ok
----------------------------------------------------------------------
Ran 12 tests in 0.219s
OK
The new style is implemented rather in lib2to3. If I point to lib/
lib2to3/tests and run
python test_parser.py
Traceback (most recent call last):
File "test_parser.py", line 12, in <module>
from . import support
ValueError: Attempted relative import in non-package
The standard error of the years to come that makes working with Python
harder and reminds me that it is not a scripting language anymore
because you can't run anything as a script not even a test.
For pedagogical reasons the behavior of test_ast.py and other standard
library tests shall show uniform behavior when called from the command
line i.e. they shall all fail with this import error message. What do
you think?