Strange path separators on Windows

前端 未结 6 915
臣服心动
臣服心动 2020-12-18 07:44

I an running this code:

#!/usr/bin/python      coding=utf8
#  test.py = to demo fault
def loadFile(path):
    f = open(path,\'r\')
    text = f.read()
    re         


        
6条回答
  •  醉酒成梦
    2020-12-18 08:22

    Use raw strings for Windows paths:

    path = r'D:\work\Kindle\srcs\test1.html'
    

    Otherwise the \t piece of your string will be interpreted as a Tab character.

提交回复
热议问题