python学习笔记:文件IO

一、读取文件内容:

def readFile(path):
    with open(path,"rt") as f:
        return f.read()

二、写入文件内容:

def writeFile(path,contents):
    with open(path, "wt") as f:
        f.write(contents)

注意:path用//而非\

猜你喜欢

转载自blog.csdn.net/xiaozhimonica/article/details/84586786
今日推荐