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 =
 dataResult = data[755:768]
 number +=1

But for some reason only 24 opens the first file and then I get an error

MB someone tell me what could be error?
March 12th 20 at 08:39
1 answer
March 12th 20 at 08:41
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