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

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

Can anyone tell me how can I do this?

12条回答
  •  温柔的废话
    2020-11-28 06:26

    Python itself can help you with this, in interactive mode:

    >>> help(file.read)
    Help on method_descriptor:
    
    read(...)
        read([size]) -> read at most size bytes, returned as a string.
    
        If the size argument is negative or omitted, read until EOF is reached.
        Notice that when in non-blocking mode, less data than what was requested
        may be returned, even if no size parameter was given.
    

提交回复
热议问题