Python Forum
problem running program in VScode - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: problem running program in VScode (/thread-9147.html)



problem running program in VScode - LavaCreeperKing - Mar-23-2018

Now that I VScode to program with I have been making some stuff and getting used to the new program but I am having one problem. I have this line of code that opens a file with pickle. The line of code that I have will run if I double click the python file or run the code from the python IDEL but when I run it from VScode it says that it can't find my file. I assume that it is not looking in the right location but I don't know how to make it look in the right location. I tried to use os.path.join to give the directory of the file but I think I did it wrong because it did not work. The file is located in the same location as my program.

This is the code. Works if I run outside of VScode.
f = open('images.lib', 'rb')
This is what I have tried but did not work.
f = open(os.path.join('C:\Users\User\Desktop\Python\New folder\Number Game','images.lib'), "rb")



RE: problem running program in VScode - buran - Mar-23-2018

don't use backslash on windows - either use forward slash or escape, e.g.
'C:\\Users\\User\\Desktop\\Python\\New folder\\Number Game'
your file is in the same folder with your script, but do you change the current working directory in VS Code integrated terminal?


RE: problem running program in VScode - LavaCreeperKing - Mar-24-2018

Thank you, I have not done much with loading files form other locations on my computer. I guess I forgot how it worked. I have only recently started using VS Code how do I check to see if my current working directory in the VS Code integrated terminal is set properly?


RE: problem running program in VScode - buran - Mar-24-2018

when you are on Terminal tab, you can see what is the current working directory. Normally it will be the same folder where the script is (i.e. if you haven't change it)


RE: problem running program in VScode - LavaCreeperKing - Mar-25-2018

Thank you.