May-29-2017, 11:56 AM
Quote:To my above question:To be honest the setup dos not look good,just mind bending
I have the following Folder and file structure:
Folder A
-FolderB
--spam.txt
--read.py
--readSpam.py
-FolderC
--foo.py
There readSpam.py has a function pick() which calls read to read the txt file.
readSpam calls read to read a txt-file in a given format, so with this module i can read spam.txt
If i want to run readspam.py i just have to use the code:
fobj = open("test.txt")
Then i can open the file and read it with read.py
But i want to do this in foo, so i include readSpam in foo and there i call:
result = readSpam.pick()
Now i get the error:
FileNotFoundError: [Errno 2] No such file or directory: 'spam.txt'
But if i put spam.txt in the same folder as foo.py the code works.
So my question is, how do i have to change my code to leave spam.txt in folder B?
![Confused Confused](https://python-forum.io/images/smilies/confused.png)
Do you have
__init__.py
in all folder as you should?So i guess you could try to give path to "spam.txt"
Folder A/FolderB/spam.txt