How to read a single character at a time from a file in Python?

后端 未结 12 783
萌比男神i
萌比男神i 2020-11-28 05:49

Can anyone tell me how can I do this?

12条回答
  •  心在旅途
    2020-11-28 06:15

    f = open('hi.txt', 'w')
    f.write('0123456789abcdef')
    f.close()
    f = open('hej.txt', 'r')
    f.seek(12)
    print f.read(1) # This will read just "c"
    

提交回复
热议问题