2014-02-23 45 views
0

python中os模塊的用途是什麼? 當需要使用它時,以及哪些類型的函數主要用於編寫Linux腳本?在python中使用os模塊來編寫腳本

+0

[Python模塊的周:'os' - 便攜式訪問操作系統的特定功能(http://pymotw.com/2/os/index.html#module-os) – jfs

回答

0

os模塊非常有用,我將舉例說明我的腳本。

import os,platform,time 
info=os.uname() 
result={'OS':info[0],'Network id':info[1],'Release':info[2],'Os Name':''.join(list(info[3].split()[0])[4:]),'Machine Type':info[4],'System Bit':platform.architecture()[0],'System Linkage':platform.architecture()[1]} 
w = open("rapport.rpt", "w") 
for key, val in result.items(): 
    w.writelines([key,' : ',val,'\n','*'*3,"*"*len(key),'*'*len(val),'\n']) 
w.writelines([time.ctime(),'!']) 
print ('Exporting......') 
time.sleep(1.5) 
w.close() 
print ('operation Finished!',w.name)