Re: file accessibility across directories?
dn via Tutor <[email protected]> Thu, 29 Feb 2024 14:45:00 +1300
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Organization | DWM |
| Message-ID | <[email protected]> |
On 29/02/24 13:06, Mats Wichmann wrote: > On 2/28/24 15:39, James Hartley wrote: >> While in the project directory: >> $ pwd >> /home/me/project >> $ cat src/foo.py >> class Foo: >> pass >> $ cat utils/baz.py >> from src.foo import Foo >> $ python utils/baz.py >> Traceback (most recent call last): >> File "./baz.py", line 1 in <module> >> from src.foo import Foo >> ModuleNotFoundError: No module named 'src' > > > When you run a script, the directory of the script is added to sys.path. > Not the directory you were in when you ran it. You can print out > sys.path in utils/baz.py to convince yourself of this. There's no src > in that directory (utils). Whereas pytest works the other way around: run from the project-directory because its (internal) 'process of discovery' will find test* files by searching the entire directory-tree... (hence the questions in earlier reply) -- Regards, =dn _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor