首页 > 技术文章 > Python 文件 I/O

JunzhaoLiang 2019-11-13 15:37 原文

文件读写

with open('Game/Dota.txt','w')as file:
    file.write('Radiant Victory! ')

当Game文件夹未创建时,出现FileNotFoundError

必须手动创建文件夹,或者用

import os
# 创建的目录
path = "Game/Valve/"
if not os.path.exists(path):
    os.makedirs(path)
模式 r r+ w w+ a a+
* *   *   *
  * * * * *
创建     * * * *
覆盖     * *    
指针在开始 * * * *    
指针在结尾         * *

 

 

推荐阅读