May-28-2017, 04:37 PM
(May-28-2017, 11:56 AM)Ewkos Wrote: But i want to do this in foo, so i include readSpam in foo and there i call:You most give folder path to spam.txt.
result = readSpam.pick()
Now i get the error:
FileNotFoundError: [Errno 2] No such file or directory: 'spam.txt'
Eg from my example:
# bar_1.py def spam(): with open('main_foo/sub/car.txt') as f: car = f.read() return 'hello from bar_1: {}'.format(car)So
car.txt
is in placed in sub folder together with bar_1.py
,but have to give it whole path to main folder.λ ptpython >>> import main_foo >>> main_foo.bar_2.goo() i am bar__2 and hello from <hello from bar_1: BMW> >>>