python中os模块常用方法

#!/usr/bin/python
## os module test

import os

print 'os.name: ', os.name
print 'os.getcwd(): ', os.getcwd()
print '''========================================='''
print 'os.getenv(\'path\'): ', os.getenv('path')
print '''========================================='''
print 'os.listdir(\'f\'): ', os.listdir('f:');

print 'os.path.isdir(\'d:\\python27\')', os.path.isdir('d:\\python27')

print 'os.path.isfile(\'d:\\python27\\xlb.py\')', os.path.isfile('d:\\python27\\xlb.py')
print 'os.path.exists(\'d:\\python27\')', os.path.exists('d:\\python27')

##这个厉害, 执行系统命令
print 'os.system(\'cmd\'): ', os.system('cmd /k net user')

posted @ 2014-03-21 22:28  harry0906  Views(202)  Comments(0)    收藏  举报