Reputation: 1
I am currently trying to make a code file that opens the files and searches the lines with inserted keywords, same kind of thing happened yesterday either. The problem is whatever I try the code doesn't find the .txt file at all. At least yesterday it had found the .txt file on my 4th try.
> ffile=input('ENTER THE FILE''S NAME...:')
fhand=open(ffile)
sayiLine=0
uzunluk=fhand.read()
for line in fhand:
sayiLine=sayiLine+1
line=line.rstrip()
if not line.starswith('A'):
continue
c=input('Dosyanda :', sayiLine,'kadar satır bulunuyor.')
d=input('Dosyanda :', uzunluk,'kadar karakter mevcut, VE BOŞLUKLAR BUNA DAHİL!!')
f=input('Son olarak dosyanda aramış olduğun tüm satırlar şunlar:')
print(line)
g=input('Çıkmak için enter tuşuna basabilirsin')
The file I want to open is in the same folder as the code
and here is the errors I get:
Sorry for the pic but the site didn't let me post the error code I am getting somehow.
Upvotes: 0
Views: 35
Reputation: 572
Seems like an encoding problem, what I suggest is to change the line:
fhand=open(ffile)
to:
fhand = open(ffile, encoding='UTF-8')
or whatever the encoding of the files you are trying to open might be.
Upvotes: 1