记忆角落

  • {{ item.name }}
  • 首页
  • 关于
  • 归档
  • 邻居
  • 捐赠

python中 os.linesep 用法

  • 郭良俊只狗
  • 2021-05-11
  • 4

os.linesep字符串给出当前平台使用的行终止符。例如,Windows使用’\r\n’,Linux使用’\n’而Mac使用’\r’。

例子:

if __name__ == '__main__':
    wd=os.getcwd()
    filetest = open (wd+'/test/test.txt', 'r+',encoding='utf-8')
    print(filetest.read())
    # 不用\n 如果使用os.linesep
    filetest.write ("\n")
    while 1:
        newline = input("Enter a line word(',' to quit):")
        if newline != ",":
            filetest.write ('%s%s' % (newline, os.linesep))
        else:
            break
    filetest.close ()
© 2012 - 2023 记忆角落 网站统计
Theme by Wing
粤ICP备14056850号-1 又拍云CDN赞助