日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

简明python教程 --C++程序员的视角(八):标准库

發(fā)布時間:2025/3/21 python 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简明python教程 --C++程序员的视角(八):标准库 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

os模塊


這個模塊包含普遍的操作系統(tǒng)功能。

如果你希望你的程序能夠與平臺無關(guān)的話,這個模塊是尤為重要的。一個例子就是使用os.sep可以取代操作系統(tǒng)特定的路徑分割符。

os.system() 執(zhí)行l(wèi)inux命令

>> os.system('ls -l')?
也可以使用subprocess模塊

?

>> subprocess.call('ls -l'.split())

os.getcwd() 得到當(dāng)前工作目錄
os.getenv()和os.putenv() 讀取和設(shè)置環(huán)境變量
os.listdir() 返回指定目錄下的所有文件和目錄名
os.remove() 刪除文件
os.system() 運行shell命令
os.path.split() 返回一個路徑的目錄名和文件名?
>>> os.path.split('/home/swaroop/byte/code/poem.txt')?
('/home/swaroop/byte/code', 'poem.txt')
os.path.isfile()和os.path.isdir() 分別檢驗給出的路徑是一個文件還是目錄
os.path.exists() 檢驗給出的路徑是否真地存在
os.linesep 給出當(dāng)前平臺使用的行終止符。?
例如,Windows使用'\r\n',Linux使用'\n'而Mac使用'\r'
os.name 指示你正在使用的平臺。?
比如對于Windows,它是'nt',而對于Linux/Unix用戶,它是'posix'。

?

?

sys模塊


sys模塊包含系統(tǒng)對應(yīng)的功能。

1. sys.argv

包含命令行參數(shù),sys.argv[0]是當(dāng)前運行的程序名稱

輸出:

?

2. sys.exit

退出正在運行的程序。和以往一樣,你可以看一下help(sys.exit)來了解更多詳情。

3. sys.stdin、sys.stdout和sys.stderr

它們分別對應(yīng)你的程序的標(biāo)準(zhǔn)輸入、標(biāo)準(zhǔn)輸出和標(biāo)準(zhǔn)錯誤流。

?

數(shù)據(jù)結(jié)構(gòu)


?

Tools for Working with Lists?里面介紹了collections.deque,bisect和heapq,都是很有用的數(shù)據(jù)結(jié)構(gòu)

?

其他


?

這里的介紹相當(dāng)有限,詳細(xì)的可以查閱The Python Standard Library和The Python Language Reference

  • 10. Brief Tour of the Standard Library
    • 10.1. Operating System Interface?(os,shutil)
    • 10.2. File Wildcards?(glob)
    • 10.3. Command Line Arguments?(sys,getopt,argparse)
    • 10.4. Error Output Redirection and Program Termination?(sys)
    • 10.5. String Pattern Matching?(re)
    • 10.6. Mathematics?(math,random)
    • 10.7. Internet Access?(urllib2,smtplib,poplib)
    • 10.8. Dates and Times?(datetime)
    • 10.9. Data Compression?(zlib,?gzip,?bz2,?zipfile?and?tarfile)
    • 10.10. Performance Measurement?(timeit,profile?and?pstats)
    • 10.11. Quality Control?(doctest,unittest)
    • 10.12. Batteries Included
      • Data interchange?csv,?xml.dom,?xml.sax
      • Internationalization?gettext,?locale, and the?codecs
      • Remote procedure calls?xmlrpclib,SimpleXMLRPCServer
      • Managing email messages?email
  • 11. Brief Tour of the Standard Library – Part II
    • 11.1. Output Formatting?(repr,pprint,textwrap,locale)
    • 11.2. Templating?(string.Template)
    • 11.3. Working with Binary Data Record Layouts?(struct,read zip file directly)
    • 11.4. Multi-threading?(threading)
    • 11.5. Logging?(logging)
    • 11.6. Weak References?(weakref)
    • 11.7. Tools for Working with Lists?(array,collections.deque(),heapq)
    • 11.8. Decimal Floating Point Arithmetic?(decimal.Decimal)

http://www.guokr.com/blog/480782/

http://docs.python.org/2/tutorial/stdlib.html

http://docs.python.org/2/tutorial/stdlib2.html

http://docs.python.org/2/contents.html

?

More Python resources:

    • http://www.python.org: The major Python Web site. It contains code, documentation, and pointers to Python-related pages around the Web. This Web site is mirrored in various places around the world, such as Europe, Japan, and Australia; a mirror may be faster than the main site, depending on your geographical location.
    • http://docs.python.org: Fast access to Python’s documentation.
    • http://pypi.python.org: The Python Package Index, previously also nicknamed the Cheese Shop, is an index of user-created Python modules that are available for download. Once you begin releasing code, you can register it here so that others can find it.
    • http://aspn.activestate.com/ASPN/Python/Cookbook/: The Python Cookbook is a sizable collection of code examples, larger modules, and useful scripts. Particularly notable contributions are collected in a book also titled Python Cookbook (O’Reilly & Associates, ISBN 0-596-00797-3.)
    • from:?http://www.cnblogs.com/wei-li/p/3438713.html

總結(jié)

以上是生活随笔為你收集整理的简明python教程 --C++程序员的视角(八):标准库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。