os

本文介绍了Python中os模块的基本用法,包括获取当前工作目录、改变工作目录及通过系统shell运行命令等操作。此外,还介绍了shutil模块提供的高级文件与目录管理功能。

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') 

 

转载于:https://www.cnblogs.com/lczit/p/4433029.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值