python文件操作

文本文件、二进制文件

python文件操作_第1张图片

解释器与硬盘(管道)

python文件操作_第2张图片

open建立管道,管道中的值决定我们得读、写、追加

OS模块

python文件操作_第3张图片

os.path

python文件操作_第4张图片

python文件操作_第5张图片

绝对路径、相对路径

相对路径:在同一级别得情况下可以往下查询

python文件操作_第6张图片

文件的复制

import os

src = r'E:\aaa\1'
target = r'E:\aaa\2'

def copy(src, target):
    if os.path.isdir(src) and os.path.isdir(target):
        listdir = os.listdir(src)
        for file in listdir:
            src_file_path = os.path.join(src, file)
            with open(src_file_path, 'r') as rStream:
                read = rStream.read()

                target_file_path = os.path.join(target, file)
                with open(target_file_path, 'w') as wStream:
                    wStream.write(read)
        else:
            print("复制完成")


copy(src, target)

你可能感兴趣的:(1024程序员节,python,开发语言)