OS module
In [2]:
import os
print os.name
print os.uname()
In [4]:
for k, v in os.environ.items():
print k,':',v
In [6]:
os.getcwd()
Out[6]:
Availability: Unix.
Availability: Unix.
Availability: Unix.
Availability: Unix.
Availability: Unix.
Availability: Unix.
Availability: Unix.
New in version 2.3.
Availability: Unix.
Availability: Unix, Windows.
Availability: Unix.
shell
命令
In [7]:
os.path.split('/User/gaufung/1.py')
Out[7]:
In [10]:
os.path.isdir(os.getcwd())
Out[10]:
In [13]:
os.path.isfile('/User/1.txt')
Out[13]:
In [14]:
os.path.exists(os.getcwd())
Out[14]:
In [15]:
os.path.exists('/User/gaofeng')
Out[15]:
In [21]:
print os.curdir
os.path.abspath(os.curdir)
Out[21]:
In [22]:
os.path.getsize(os.getcwd())
Out[22]:
In [24]:
os.path.splitext('1.txt')
Out[24]:
In [28]:
os.path.join('/Users','gaofeng','1.txt')
Out[28]:
In [30]:
path = '/Users/gaufung/1.txt'
print os.path.basename(path)
print os.path.dirname(path)