os

python .27

os Miscellaneous operating system interfaces(各种各样的操作系统接口)

os模块提供了几十个函数与操作系统交互:

>>>
>>> import os
>>> os.getcwd()      # Return the current working directory
'C:\\Python26'
>>> os.chdir('/server/accesslogs')   # Change current working directory
>>> os.system('mkdir today')   # Run the command mkdir in the system shell
0

内置的dir()help()函数对于使用像os大型模块可以作为非常有用的交互式帮助:

>>>
>>> import os
>>> dir(os)
<returns a list of all module functions>
>>> help(os)
<returns an extensive manual page created from the module's docstrings>

对于日常的文件和目录管理任务,shutil模块提供了一个易于使用的高级接口:

>>>
>>> import shutil
>>> shutil.copyfile('data.db', 'archive.db')
>>> shutil.move('/build/executables', 'installdir')

 

posted @ 2015-04-16 19:21  zhek  阅读(365)  评论(0编辑  收藏  举报