How to read text from all files in Python?

You have the following program code
from os import listdir

fileNames = listdir(r'C:\Users\sha\Desktop\27')
handleWrite = open(r'C:\Users\sha\Desktop\27\fileResult\Result.txt', 'w')
number = 0
for cycle in fileNames:
 q = fileNames[number]
 handle = open(r'C:\Users\sha\Desktop\27\{}'.format(q), 'r')
 data = handle.read(768)
 dataResult = data[755:768]
print(dataResult)
handle.close()
handleWrite.write('{}\n'.format(dataResult))
 number +=1
handleWrite.close()

But for some reason only 24 opens the first file and then I get an error
spoiler
5bbee77d9d903675963003.png

MB someone tell me what could be error?
March 12th 20 at 08:39
1 answer
March 12th 20 at 08:41
Solution
try encoding to specify file = open(filename, encoding="utf8")
Thanks for help, I think that those files that are not read, they are somehow highlighted differently to the Sublime. Thank you. Have a good day. - maddison50 commented on March 12th 20 at 08:44
@maddison50, Not for that, have a nice day - eleaza commented on March 12th 20 at 08:47

Find more questions by tags PyCharmPython