I have a python script say "foo_1.py" which resides in folder x and another script foo_2.py which resides in folder y.
Folders x and y are in folder z.
I called a method which belongs to foo_2.py which generates an image in folder y (say img1.png). Now what I want is to access this img1.png from foo_1.py. How is it possible?
sys.path[0] gives you the directory where the current script resides:
import sys, os
script_dir = sys.path[0]
img_path = os.path.join(script_dir, '../y/img1.png')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With