廢話不多說,直接上代碼,取得當(dāng)前目錄:
path = os.path.dirname(sys.argv[0])
遍歷當(dāng)前目錄:
def traveldir(root_dir):
for dir_or_file in os.listdir(root_dir):
path = os.path.join(root_dir, dir_or_file)
print path
if os.path.isdir(path):
traveldir(path)
csv文件讀寫:
import csv
csv_data = csv.reader(open("filename.csv"))
for line in csv_data:
print line