Re: file accessibility across directories?

Mats Wichmann <[email protected]> Wed, 28 Feb 2024 17:06:13 -0700
Newsgroups gmane.comp.python.tutor
Message-ID <[email protected]>
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).
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor