python 的一些小功能偶尔用一下不太能记住,总是临时去查,觉着也麻烦。昨天有需要得到路径里的文件名,记录一下 。
import os f = "a/b/c/d.txt" name, ext = os.path.splitext(f) print name, ext print os.path.dirname(f) print os.path.basename(f)
结果
a/b/c/d .txt a/b/c d.txt
还有写文件
output = open("op.txt", "w") output.write("You’re still goin’ strong") output.close()
0 条评论。