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.

Recommended Answers

All 2 Replies

open("../folderb/img.png")

or (safer, cross platform)

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

Thanks but I've solved it a different way :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.