Message107403
Attempting to change the working directory and then import based on that change has no effect. Import seems impossible. Attached is tarball example. As seen below, bar1.py can import foo from src, however bar2.py bar3.py and bar4.py cannot, despite their respective scripts changing their cwd. Below is results of a terminal session. Thanks in advance.
james@hostname:~$ tree import_bug/
import_bug/
|-- bar1.py
|-- __init__.py
|-- src
| |-- foo.py
| `-- __init__.py
`-- test
|-- bar2.py
|-- bar3.py
|-- bar4.py
|-- bar5.py
`-- __init__.py
2 directories, 9 files
james@hostname:~$ cat import_bug/src/foo.py
# this is foo.py
print('this is foo.py')
james@hostname:~$ cat import_bug/bar1.py
# this is bar1.py
import os
print(os.getcwd())
from src import foo
print('this is bar1.py')
james@hostname:~$ cat import_bug/test/bar2.py
# this is bar2.py
import os
os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
print(os.getcwd())
from src import foo
print('this is bar2.py')
james@hostname:~$ python import_bug/bar1.py
/home/james
this is foo.py
this is bar1.py
james@hostname:~$ python import_bug/test/bar2.py
/home/james/import_bug
Traceback (most recent call last):
File "import_bug/test/bar2.py", line 7, in <module>
from src import foo
ImportError: No module named src
james@hostname:~$ |
|
Date |
User |
Action |
Args |
2010-06-09 15:44:15 | purpleidea | set | recipients:
+ purpleidea |
2010-06-09 15:44:15 | purpleidea | set | messageid: <1276098255.67.0.264247838489.issue8955@psf.upfronthosting.co.za> |
2010-06-09 15:44:14 | purpleidea | link | issue8955 messages |
2010-06-09 15:44:12 | purpleidea | create | |
|