The problem of enurmate reading files in python

self.official_account = os.getcwd () + "/" + "official_account.rtf"
for index,content in enumerate (open (self.official_account,"r")):

        print(content,end="")

clipboard.png


i love you
ich liebe dich
heissen dank

clipboard.png

Mar.23,2021

is your rtf file with one word and one line.

In [6]: 
   ...: for i, l in enumerate(open('haha.txt')):
   ...:     print(l, end="")
   ...: 
hello world
miao
haha

there is no problem with my test


I don't think you need to subscript the list of requirements. You don't need to use enumerate, and just use the for loop. The former is less efficient than the latter.

>>> import timeit
>>> timeit.timeit('for i in xrange(100): a[i]', 'a = list(xrange(100))')
7.2920000553131104
>>> timeit.timeit('for i, o in enumerate(a): o', 'a = list(xrange(100))')
10.359999895095825
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e41989-438c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e41989-438c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?