0

I am using pygame and I am trying to locate my folder but it won't locate it!
The command I am using is:

Game_folder = os.path.dirname(__file__)

Or

Game_folder = os.path.dirname(is.path.abspath(__file__))

Neither of these work.

I am trying to locate the directory:

C:/Users/user/Documents/python/pygame games

It prints out:

Python.exe can't open C:/Users/user/Documents/python/pygame games.py 

exit code 2

This error appears for both of the codes.

I am using PyCharm as my IDE And my imports are pygame, random, os

I can't progress without it and I am following along with a playlist on YouTube (kidscancode), but the video is a bit older so I have to search up on the internet on how to adapt the code.

Omar Einea
  • 2,478
  • 7
  • 23
  • 35
Tudor Popescu
  • 509
  • 1
  • 5
  • 16
  • 3
    I don't think 'python-requests' is an appropriate tag here, that's for questions about the Requests HTTP library. – Personman Feb 02 '18 at 18:33
  • It is impossible to provide help with the problem given the available information. `os.path.dirname(file)` will give you the directory in which `file` is, if `file` is a valid filename. It probably is not. You should give a minimal, complete and verifiable example of your problem. See https://stackoverflow.com/help/mcve – zvone Feb 02 '18 at 18:37
  • I can't access my computer rn but when I will be able to access it I will post a comment – Tudor Popescu Feb 02 '18 at 18:43
  • @Personman sorry about that, I'm not educated on where specifically where the problem is but I will search it up next time – Tudor Popescu Feb 02 '18 at 18:44
  • [link](https://ufile.io/gf6r5) the file – Tudor Popescu Feb 02 '18 at 18:50
  • 1
    do not provide download links to file - please share "a minimal, complete and verifiable example" in the question. What will happen if you will provide different folder than "C:/Users/user/Documents/python/pygame games"? – jozefow Feb 02 '18 at 18:58
  • From what I can see, this is not a problem with your python code. I expect there is something wrong with the Pycharm settings (it is trying to open `C:/Users/user/Documents/python/pygame games.py` while it should try to open `C:/Users/user/Documents/python/pygame games/first-game.py`). – Joost Huizinga Feb 02 '18 at 19:00
  • @JoostHuizinga im actually trying to open the directory(folder) not the actual py file – Tudor Popescu Feb 02 '18 at 19:05
  • @Tudor Popescu Yes, you have code that tries to open a folder. However, I don't think your code is actually executed at any point, and I expect the error happens before your code is executed. One thing you can try is to make a copy of your code, then delete and replace all code with a simple `print("Test")`. That should tell you whether the bug is even related to your code. – Joost Huizinga Feb 02 '18 at 20:07
  • @JoostHuizinga I did that and it just printed Test, there are no bugs in my knowledge as pycharm is really good at sporting them and the error only appeared when trying to load an image – Tudor Popescu Feb 02 '18 at 20:11
  • @Tudor Popescu In that case, I do not know what the issue is. All I can say is that the error message you report is not the error message pygame will throw when it can not load an image. – Joost Huizinga Feb 02 '18 at 20:23
  • Don't worry anymore I replaced that specific code again and it worked, it was wierd – Tudor Popescu Feb 02 '18 at 20:36

0 Answers0