I am opening a file but it shows file not exist even if it exists | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I am opening a file but it shows file not exist even if it exists

Solve

25th Jun 2020, 4:37 PM
ALL IN ONE GYAN
ALL IN ONE GYAN - avatar
11 Answers
+ 7
Please show us your code, that may help to find the issue. Also name the platform you are working on (Windows, Android, Apple, Linux) Thanks!
25th Jun 2020, 5:07 PM
Lothar
Lothar - avatar
+ 5
The error occurs, because try: always need a valid except: block. ... try: print("done") except Exception as e: print(e)
27th Jun 2020, 1:09 PM
Lothar
Lothar - avatar
+ 4
ALL IN ONE GYAN, i took your code as it is, and pasted it in a local IDE, and created the required txt files in the same directory. Both versions are running without any problem The codes are the same, except the for loop, but this has no influence on reading the files. If you try to run the codes in playground, both of them will fail, as the files do not exist.
26th Jun 2020, 9:38 AM
Lothar
Lothar - avatar
+ 3
Who will tell the information about language. Use cmd or terminal to get its Path . I think you would get it like that . I use mobile so that I use pydroid3 for finding the path of file.
25th Jun 2020, 4:47 PM
Ayush Kumar
Ayush Kumar - avatar
+ 3
Use appropriate tags for more read on : https://www.sololearn.com/Discuss/333866/?ref=app
25th Jun 2020, 5:32 PM
Daljeet Singh
Daljeet Singh - avatar
+ 3
So you are absolutely sure that the desired files are in the same directory as the python file and also have the correct name and you also have access rights to them?
26th Jun 2020, 2:24 PM
Lothar
Lothar - avatar
0
"""I am using pydroid3""" f=open("n1.txt") print (f.read()) f.close() g=open("n2.txt") print (g.read()) g.close() h=open("n3.txt") print (h.read()) h.close() i=open("n4.txt") print (i.read()) i.close() j=open("n5.txt") print (j.read()) j.close() """This code doesn't shows me error but the next one shows file doesn't exist""" n=int(input()) a=0 while(a!=n): a=a+1 print("*"*a) f=open("n1.txt") print (f.read()) f.close() g=open("n2.txt") print (g.read()) g.close() h=open("n3.txt") print (h.read()) h.close() i=open("n4.txt") print (i.read()) i.close() j=open("n5.txt") print (j.read()) j.close() """This code shows no file file exists."""
26th Jun 2020, 3:05 AM
ALL IN ONE GYAN
ALL IN ONE GYAN - avatar
0
But I am using pydroid3 it doesn't work on it
26th Jun 2020, 9:45 AM
ALL IN ONE GYAN
ALL IN ONE GYAN - avatar
0
Yes
26th Jun 2020, 2:25 PM
ALL IN ONE GYAN
ALL IN ONE GYAN - avatar
0
a=int(input()) if a==1: print("Whose data you want to log in.") b=input() print("What data you want to log\n1.Diet\n2.Excersice") c=int(input()) if c==1: d=="d" elif c==2: d=="e" try: print("done") Why this file is showing EOF error when using try.pls help
26th Jun 2020, 2:27 PM
ALL IN ONE GYAN
ALL IN ONE GYAN - avatar
0
Problem is with 'try:' and the next line. If you cut that, the code is running fine.
27th Jun 2020, 4:55 AM
Mir Abir Hossain
Mir Abir Hossain - avatar