Quantcast
Channel: 葡萄成熟时 » Glory Wu
Viewing all articles
Browse latest Browse all 20

Python标准库之os模块

$
0
0

1、删除和重命名文件

import os
import string

def replace(file, search_for, replace_with):
    # replace strings in a text file

    back = os.path.splitext(file)[0] + ".bak"                            (1)
    temp = os.path.splitext(file)[0] + ".tmp"

    try:
        # remove old temp file, if any
        os.remove(temp)                                                  (2)
    except os.error[......]

继续阅读


Viewing all articles
Browse latest Browse all 20

Trending Articles