立即学习:https://edu.csdn.net/course/play/25505/306022?utm_source=blogtoedu
#!/usr/bin/python
# -*- coding: gbk -*-
import random, os
path = os.path.dirname(__file__)
with open(r'./txt/index.txt', 'r') as txt:
a = txt.read()
print(a)
name = txt.name
name = name[name.rfind('/')+1:]
print(name)
path = os.path.join(path, name)
print(path)
with open(path, 'w') as txt1:
txt1.write(a)
复制一个文件
import random, os
pat = os.path
path = os.path.dirname(__file__) # 文件夹名
print(path)
result = os.path.split(path) # 分割文件名
print(result)
path = pat.join(path, 'a', 'b', 'c') # 拼接文件名
print(path)
path = './index.py'
result = pat.splitext(path) # 获取后缀名
print(result)
result = pat.getsize(path) # 返回大小单位字节
print(result)