Recently got a new laptop, with that needed to transfer over my programs and projects. I made and then cloned a private repository on GitHub onto my new laptop, however anytime I run a program that needs to access any .txt files I get the same error. The .txt files are in the same folder as the program and it runs on my old laptop completely fine. Also any program that does not need to search for any external files works just fine. Provided a picture that shows the folder and the error given. folder
error
Tried reinstalling VSCode, did not fix it. I assume I made a mistake with the the git repository or something. Appears to be a path issue of some sorts but was unable to find a solution online.
Edit: Relatively new to programming, also wanting to avoid hardcoding the absolute path as I am in school and my program needs to run on the markers computer.
3
Answers
You can note that the current folder in terminal is the worksapce instead of the folder where the file you ran was.
You can use the following codes to open:
You can also add the path of klingon-english.txt to environment variable.
Try this. Right click on your text file which you want to open and copy path as shown. Now paste this path in your
open
function on python file where you have.to avoid hard coding the full path, you can use
os.getcwd()
like this:The function
os.getcwd()
gets you a string of the current working directory.