Python os.mkdir() 方法
python os.mkdir() 方法
os.mkdir() 方法用于以數(shù)字權(quán)限模式創(chuàng)建目錄。默認(rèn)的模式為 0777 (八進(jìn)制)。
如果目錄有多級(jí),則創(chuàng)建最后一級(jí),如果最后一級(jí)目錄的上級(jí)目錄有不存在的,則會(huì)拋出一個(gè) oserror。
語法
mkdir()方法語法格式如下:
os.mkdir(path[, mode])
參數(shù)
- path -- 要?jiǎng)?chuàng)建的目錄,可以是相對(duì)或者絕對(duì)路徑。
- mode -- 要為目錄設(shè)置的權(quán)限數(shù)字模式。
返回值
該方法沒有返回值。
實(shí)例
以下實(shí)例演示了 mkdir() 方法的使用:
#!/usr/bin/python # -*- coding: utf-8 -*- import os, sys # 創(chuàng)建的目錄 path = "/tmp/home/monthly/daily/hourly" os.mkdir( path, 0755 ); print "目錄已創(chuàng)建"
執(zhí)行以上程序輸出結(jié)果為:
目錄已創(chuàng)建
相關(guān)文章
- Python 文件I/O
- Python 面向?qū)ο?/a>
- Python 操作 MySQL 數(shù)據(jù)庫
- Python2 與 Python3?? 版本區(qū)別
- Python JSON
- Python 環(huán)境
- Python 數(shù)組
- Python 列表
- Python 二維數(shù)組
- Python 集合
- Python 哈希表
- Python3 教程
- Python3 簡(jiǎn)介
- Python3 數(shù)字(Number)
- Python3 OS 文件/目錄方法
- Python3 作用域
- Python3 正則表達(dá)式
- Python3 SMTP發(fā)送郵件
- Python3 MySQL 數(shù)據(jù)庫連接 - PyMySQL 驅(qū)動(dòng)
- Python MongoDB 數(shù)據(jù)庫連接 - PyMongo 驅(qū)動(dòng)