Home  >  Q&A  >  body text

getchar - diffrent of Python readline() and C getc()

巴扎黑巴扎黑2711 days ago472

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:32:21

    You can try the f.read(size) function. If size is set to 1, it will read character by character, and then filter the data.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:32:21

    This is easy to usepython, but the result is the same, it’s because your posture is not right

    For example, the content you filtered> twiiiiiii@2, 我模拟一下, 假如待处理的文件(raw.dat) is as follows

    > t我w爱i北i京i天i安i门ii@2

    Up code

    with open("raw.dat", "rb") as fh:
        line = fh.readline()
        print(line)
        print(line.decode('ascii', 'ignore'))
    

    Output

    b'> t\xce\xd2w\xb0\xaei\xb1\xb1i\xbe\xa9i\xcc\xeci\xb0\xb2i\xc3\xc5ii@2'
    > twiiiiiii@2

    So there’s no problem, it’s no different from what you use C

    reply
    0
  • Cancelreply