Python: Standard Library - Operating System Interface

os module provides a number of functions related to the operating system with it.

os Import
os.getcwd () # returns the current working directory
'C: \ Python34'

os.chdir ( '/ server / accesslogs' ) # Change the current working directory
os.system ( 'mkdir today') # execute system commands mkdir
0

We recommend the use of "import os" style instead of "from os import *". This ensures that with different operating systems vary in os.open () does not cover the built-in function open ().

When built using such a large module os dir () and help () functions are useful:

the amount
dir (os)

help(os)
<returns an extensive manual page created from the module’s docstrings>

For daily file and directory management tasks,: mod: shutil module provides a higher level interface that is easy to use:

import shutil
shutil.copyfile(‘data.db’, ‘archive.db’)
shutil.move(’/build/executables’, ‘installdir’)

Guess you like

Origin blog.csdn.net/weixin_44523387/article/details/92161953