當前位置:成語大全網 - 新華字典 - 如何學習python的os模塊

如何學習python的os模塊

壹、os模塊概述

Python os模塊包含普遍的操作系統功能。如果妳希望妳的程序能夠與平臺無關的話,這個模塊是尤為重要的。(壹語中的)

二、常用方法

1、os.name

輸出字符串指示正在使用的平臺。如果是window 則用'nt'表示,對於Linux/Unix用戶,它是'posix'。

2、os.getcwd()

函數得到當前工作目錄,即當前Python腳本工作的目錄路徑。

3、os.listdir()

返回指定目錄下的所有文件和目錄名。

>>> os.listdir(os.getcwd())

['Django', 'DLLs', 'Doc', 'include', 'Lib', 'libs', 'LICENSE.txt', 'MySQL-python-wininst.log', 'NEWS.txt', 'PIL-wininst.log', 'python.exe', 'pythonw.exe', 'README.txt', 'RemoveMySQL-python.exe', 'RemovePIL.exe', 'Removesetuptools.exe', 'Scripts', 'setuptools-wininst.log', 'tcl', 'Tools', 'w9xpopen.exe']