How to write native newline character to a file descriptor in Python?

前端 未结 2 400
粉色の甜心
粉色の甜心 2020-12-14 06:11

The os.write function can be used to writes bytes into a file descriptor (not file object). If I execute os.write(fd, \'\\n\'), o

相关标签:
2条回答
  • 2020-12-14 07:02

    Use this

    import os
    os.write(fd, os.linesep)
    
    0 讨论(0)
  • 2020-12-14 07:04

    How about os.write(<file descriptor>, os.linesep)? (import os is unnecessary because you seem to have already imported it, otherwise you'd be getting errors using os.write to begin with.)

    0 讨论(0)
提交回复
热议问题