New submission from James <[email protected]>:
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.
ja...@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
ja...@hostname:~$ cat import_bug/src/foo.py
# this is foo.py
print('this is foo.py')
ja...@hostname:~$ cat import_bug/bar1.py
# this is bar1.py
import os
print(os.getcwd())
from src import foo
print('this is bar1.py')
ja...@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')
ja...@hostname:~$ python import_bug/bar1.py
/home/james
this is foo.py
this is bar1.py
ja...@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
ja...@hostname:~$
----------
components: Library (Lib)
files: import_bug.tar
messages: 107403
nosy: purpleidea
priority: normal
severity: normal
status: open
title: import doesn't notice changes to working directory
versions: Python 2.6, Python 3.1
Added file: http://bugs.python.org/file17600/import_bug.tar
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue8955>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com