#๐ My file is not recognised
72 messages ยท Page 1 of 1 (latest)
@lofty sinew
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Error??
show what exactly are you running, and which error exactly are you getting
how are you running it?
Bye clicking on run
do python3 main.py
see which command is it running in the terminal
Ok
Not working
It's saying no file is recognised
error?
odds are that the current working directory is different from the folder you created those files in
for example, if you have:
/a/b/c.py
and the terminal is sitting in the a folder, then you have to either change to the b folder, or explicitly tell it that the file you want to interact with is inside of that folder
bruh
the working directory is ...Desktop/pyparv, the file you are trying to run is ...Desktop/pypvarv/file handling/main.py
You must either cd "file handling" first, or pass the full path to main.py instead of only the name
also install discord on your computer if you can
Installed
pasting as text > printscreen > literal picture
Ok
Oooh
I understand
But now it is not printing file content
@tepid karma
PS C:\Users\cc\Desktop\pyparv> & C:/Users/cc/AppData/Local/Programs/Python/Python313/python.exe "c:/Users/cc/Desktop/pyparv/file handling/main.py"
more or less the same issue as before
your working directory is still pyparv, so when you do open('parv.txt') it looks for pyparv/parv.txt
you have to either change the path inside of main.py, or change your working directory
i updated the cod see
and change the path to the path of your txt
in the script
file=open("file handling/parv.txt","r")
f=file.read()
print(f)
how to change working directory
?
using a context manager is good practice, but shouldn't make much of a difference here
the biggest difference is just that it closes the file automatically for you
the last code block you posted should work, but you can use the cd command in the terminal or modify the VS Code settings
not worked that code
@tepid karma
Can you say in which directory is the parv.txt?
pyparv
show the full thing being ran in the terminal and the error
it wouldnt, cuz on photo he sent earlier the script was in file handling/
and it gives error 2
file=open("../parv.txt","r")
f=file.read()
print(f)
try maybe this
This
Should work
if it is in pyparv directory
-- pyparv/file handling/main.py
with open('parv.txt', 'r') as file:
print(file.read())
-- pyparv/file handling/parv.txt
hello world
-- type in the terminal:
cd "file handling"
py main.py
problem is parv.txt is not in file handling
oh
my bad
It's in file handling I put it
Ok so it should now then
try this now
I am very thankful to both of you but it's 12:05 am I should go to sleep and turn off my laptop i will surely solve it tomorrow
good night
Thankyou for helping me
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.