0

Say I have a file structure that looks like this

root folder/
    main.py
    -folder a
        -script.py
    -folder b
        -img.png

How could I load the img.png file from script.py?
Should I just have a function in main.py that gets the path of the root folder, and then tac the 'folder a' and 'folder b' bit on?

Thanks for your time.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by SgtMe
0
open("../folderb/img.png")

or (safer, cross platform)

import os
path = os.path.join("..", "folderb", "img.png")
open(path)

Edited by ultimatebuster: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.