小编典典

如何一次从Python文件中读取单个字符?

python

谁能告诉我该怎么做?


阅读 222

收藏
2020-12-20

共1个答案

小编典典

with open(filename) as f:
  while True:
    c = f.read(1)
    if not c:
      print "End of file"
      break
    print "Read a character:", c
2020-12-20