Python 文件 I/O

文件读写

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+
* *   *   *
  * * * * *
创建     * * * *
覆盖     * *    
指针在开始 * * * *    
指针在结尾         * *

猜你喜欢

转载自www.cnblogs.com/JunzhaoLiang/p/11849933.html