#๐Ÿ”’ My file is not recognised

72 messages ยท Page 1 of 1 (latest)

lofty sinew
#

Help me

dusky elkBOT
#

@lofty sinew

Python help channel opened

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.

lofty sinew
#

I made a file named main.py and parv.txt in a folder but file is not recognised

cold oriole
#

Error??

tepid karma
lofty sinew
#

Ok

#

file=open("parv.txt","r")
f=file.read()
print(f)

tepid karma
#

how are you running it?

lofty sinew
tepid karma
lofty sinew
cold oriole
tepid karma
lofty sinew
#

Ok

lofty sinew
lofty sinew
cold oriole
cold oriole
#

The output

tepid karma
#

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

lofty sinew
cold oriole
tepid karma
# lofty sinew

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

lofty sinew
tepid karma
#

pasting as text > printscreen > literal picture

lofty sinew
#

Ok

lofty sinew
#

I understand

#

But now it is not printing file content

#

@tepid karma

cold oriole
#

Whats the error?

#

Or just empty

lofty sinew
#

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"

cold oriole
#

with open("parv.txt", "r") as file:
f = file.read()
print(f)

#

try this

tepid karma
#

you have to either change the path inside of main.py, or change your working directory

lofty sinew
#

i updated the cod see

cold oriole
#

in the script

lofty sinew
#
file=open("file handling/parv.txt","r")
f=file.read()
print(f)    
lofty sinew
#

?

tepid karma
tepid karma
lofty sinew
#

@tepid karma

cold oriole
lofty sinew
#

pyparv

cold oriole
#

like desktop/โ€ฆ. etc

tepid karma
cold oriole
#

and it gives error 2

#
file=open("../parv.txt","r")
f=file.read()
print(f)    
#

try maybe this

cold oriole
#

if it is in pyparv directory

tepid karma
#
-- 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
cold oriole
tepid karma
cold oriole
lofty sinew
cold oriole
lofty sinew
#

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

cold oriole
#

good night

lofty sinew
#

Thankyou for helping me

dusky elkBOT
#
Python help channel closed using Discord native close action

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.