新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:怎么創(chuàng)建python腳本文件夾
創(chuàng)建文件夾

成都創(chuàng)新互聯(lián)從2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站建設(shè)、網(wǎng)站制作網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元??底鼍W(wǎng)站,已為上家服務(wù),為??蹈鞯仄髽I(yè)和個人服務(wù),聯(lián)系電話:18982081108
import os def mkdir(path): folder = os.path.exists(path) if not folder: #判斷是否存在文件夾如果不存在則創(chuàng)建為文件夾 os.makedirs(path) #makedirs 創(chuàng)建文件時(shí)如果路徑不存在會創(chuàng)建這個路徑 print "--- new folder... ---" print "--- OK ---" else: print "--- There is this folder! ---" file = "G:\\xxoo\\test" mkdir(file) #調(diào)用函數(shù)
推薦學(xué)習(xí)《Python教程》
os.getcwd()可以查看py文件所在路徑;
在os.getcwd()后邊 加上 [:-4] + 'xxoo\\' 就可以在py文件所在路徑下創(chuàng)建 xxoo文件夾
import os folder = os.getcwd()[:-4] + 'new_folder\\test\\' #獲取此py文件路徑,在此路徑選創(chuàng)建在new_folder文件夾中的test文件夾 if not os.path.exists(folder): os.makedirs(folder)
創(chuàng)建txt文件
在桌面創(chuàng)建一個名字為 new 的txt文件
import os
file = open('C:\\Users\Administrator\\Desktop\\' + 'new' + '.txt','w')
file.close() 當(dāng)前題目:創(chuàng)新互聯(lián)Python教程:怎么創(chuàng)建python腳本文件夾
文章分享:http://fisionsoft.com.cn/article/ccedijc.html


咨詢
建站咨詢
