python檔案練習(二)

2021-09-14 02:26:10 字數 726 閱讀 8719

import os

#作業系統模組

print(os.name)

print(os.getcwd())

os.mkdir("f:\\x")#建立目錄

os.makedirs("f:\\y\\z")#建立多級目錄

print(os.listdir("f:\\tom"))#將目錄,檔案返回為列表

os.rmdir("f:\\x")# 刪除目錄

#os.remove("f:\\x")

os.removedirs("f:\\y\\z")#刪除子目錄

os.chdir("f:")#切換到f目錄

#os.mkdir("001")#絕對路徑建立目錄

#os.mknod("001\\x.txt")無法建立空檔案

print(os.getcwd())

#os.chdir("f:\\001")

#os.mknod("00.txt")#當前資料夾下建立檔案

fp=open("001\\00.txt","w")

fp.close()

nt

c:\users\pycharmprojects\test001\test

['apache-tomcat-8.5.38-windows-x64', 'apache-tomcat-8.5.38-windows-x64.zip']

f:\

python 檔案讀寫練習

練習包括 讀取與寫入 usr bin env python coding utf 8 time 2017 10 30 0030 08 58 file lianxi2.py 正向排序 import codecs l 1,5,3,8,2,4 l.sort 寫入檔案 with codecs.open 1....

Python檔案練習(一)

import os dir f mydir001 f os.mkdir dir 建立資料夾 s hello everyone l n改換行啦 寫入檔案,使用追加寫方式,此處注意資料夾連線方式 with open dir 002.txt a as file file.write s file.writ...

python練習 讀寫檔案

對於不同的作業系統,檔案目錄會有不同,對於linux而言,萬事萬物皆檔案 對windows而言,檔案讀寫也很重要。import os 拼接路徑 os.path.join usr bin spam 返回路徑 usr bin spam 兩個倒斜槓等價於乙個正斜槓 獲得當前工作目錄 os.getcmd 相...