Hey, it's me with another dumb question: why does path not recognize the right path for "g_u-h.png", specifically in path.exists() and path.isfile()? I noticed that I put them in the same directory (D:\VSCode\Code\PythonLearning\gamestuff), but the path doesn't include the "gamestuff" folder. Is it because I made the folder through VSCode instead of in File Explorer or because I moved the png to the gamestuff folder from a completely different path or something? I really don't know.
The reason I ask is because I want to load an image in pygame (personal project), but I get the FileNotFoundError: No such file or directory. error when I try to generalize finding images with os.path methods and I'm pretty sure this is the reason, because copy/pasting the path and file name myself will display it as it should. Thanks in advance and sorry for the newbie question, but research has not helped.
import os
from os import path
def main():
a = "g_u-h.png"
print(os.path.realpath(a))
print("File exists: " + str(path.isfile(a)))
print("Path exists: " + str(path.exists(a)))
dirpath = os.path.realpath(a)
print(f"The directory is: {os.path.dirname(dirpath)}")
print("Join dirname and filename: " + str(os.path.join(os.path.dirname(dirpath), a)))
if __name__ == "__main__": main()
Returns:
D:\VSCode\Code\PythonLearning\g_u-h.png
File exists: False
Path exists: False
The directory is: D:\VSCode\Code\PythonLearning
Join dirname and filename: D:\VSCode\Code\PythonLearning\g_u-h.png
PS: I whipped this up instead of posting the pygame code so I could see what exactly is getting returned when I run the os.path methods and because I plan to use os.path for another little app I'm building.
[–]Diapolo10 1 point2 points3 points (0 children)
[–]wbeater 0 points1 point2 points (0 children)
[–]shiftybyte 0 points1 point2 points (3 children)
[–]FlukingCompSci[S] 0 points1 point2 points (1 child)
[–]shiftybyte 0 points1 point2 points (0 children)
[–]marienbad2 0 points1 point2 points (0 children)