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

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

Can anyone tell me how can I do this?

12条回答
  •  盖世英雄少女心
    2020-11-28 06:07

    This will also work:

    with open("filename") as fileObj:
        for line in fileObj:  
            for ch in line:
                print(ch)
    

    It goes through every line in the the file and every character in every line.

提交回复
热议问题