[Tutor] File path requirements (absolute or relative)?
Peter Otten
__peter__ at web.de
Fri May 15 17:46:25 EDT 2020
boB Stepp wrote:
> My file structure for a project is as follows:
>
> ~
> | Projects
> | project_name
> | docs
> | src
> project_name.py
> | tests
> test.py
> test_csv_file.csv
>
> I wish to pass the path for "test_csv_file.csv" from the test.py program
> to
> the function in src/project_name.py which processes csv files. Ideally I
> would like to use a relative path name like "../tests/test_csv_file" and
For that to work the current working directory has to be src, or docs, or
tests.
If you want to be independent from the working directory you can determine
the directory containing tests.py from within tests.py with
os.path.dirname(__file__).
> have the function in src/project_name.py to be able to use it. But so far
> all of my efforts to use a relative path name have failed. Even
> "~/Projects/project_name/tests/test_csv_file.csv" fails. Only when I use
> the absolute path name
> "/Home/bob/Projects/project_name/tests/test_csv_file.csv" does the test
> complete successfully. What am I misunderstanding?
>
More information about the Tutor
mailing list