'Cross platform Python file handleing
I have three python file and two text files file in respective folders.
- A.py in folder A, which is the main file
- B.py and b_results.txt in folder B
- C.py and c_results.txt in folder C
Intentions:
- File A.py will call a Class b_class() in B.py (via from B import b_class)
- b_class will work with text form b_results.txt and a call Class c_class in C.py (b.py has top level import from C import * )
- c_class need some data form c_results.txt it dose its thing and returns value to b_class
- Then b_class will DoSomeThing with both results and spit it to A.py. Where the results are displayed.
Prob: What's happening is each file is being executing perfectly in it's respective folder. C.py is reading c_results.txt and B.py is reading b_results.txt since c_class is called as an instance in b_class. c_class is looking for file c_results. txt in folder B.
Tried methods:
- Relative paths in [OS, phatlib] : No such file or directory: 'c_results.txt'
- Absolute paths in [OS, phatlib] : Not working in other machine (Windows/ Mac/ linux)
- init.py (included .py and .txt) : Not working in cross platform
Pictorial representation of the struggle
I understand it's calling an instance of a class but I'm not able to find a method to make it work in a professional way (by this i mean writing everything in one.py and copy the respective contents to the cwd() then remove() them before exit).
Can someone tell me how it's done.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
