Hello! I’m extremely new to coding and using VS code so please bear with me. I am trying to run a simple madlibs generator however, in the terminal it states that my story file isn’t in the same directory as my madlibs generator file. But when I look over and look at references, I’m under the impression that they are within the same directory. Can anyone help?
#Help please I’m brand new
29 messages · Page 1 of 1 (latest)
Couldn't you just take screenshot and post it here?
It's hard to see from the monitor.
Anyway, try ./story.txt instead of just story.txt on the filepath.
You are running the python code from another folder, so it'll assume story.txt is in your current directory.
Since most people would be running scripts from the root dirctory, the best practice would be setting a ROOT constant and set your filepath from there.
I’m very unfamiliar with all of these terms, for starters, why is it saying “./story.txt” is not valid as a file or folder name?
Also my apologies for the shotty pictures, I will screenshot next time
Screenshot the piece of code where you load "story.txt"
Not that one
The one in python code
Where do you think the error comes from?
Not the text file itself.
The error message will tell you where is it.
You're right, im sorry, just getting overwhelmed because i have been at this for awhile and still cannot find a solution
So you tried putting "./story.txt" but it didn't work?
Could you try again and give me the error message?
yes i will try again and show you what it shows me
im sorry if this seems really dumb or if I am messing up horrendously, i've just been stuck and still extremely new. co pilot, google, nothing has been much help
Run from your terminal instead of using the Run tool
Run tool uses the project directory as working directory
Alternatively, use absolute paths or paths relative to the current files path
- Follow what Sylte said and read some guides about it.
- Don't change the file name
Change the first line of the code to
with open("./story.txt", "r") as f:
These are very basic things, you need to identify what's the problem and read about it.
Using AI won't get you far.
The piece of code I sent you was using relative paths.