简明python教程 --C++程序员的视角(八):标准库
来源:互联网 发布:ubuntu 16.04 中文字体 编辑:程序博客网 时间:2024/04/25 14:45
os模块
这个模块包含普遍的操作系统功能。
如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的。一个例子就是使用os.sep可以取代操作系统特定的路径分割符。
os.system()执行linux命令>> os.system(
'ls -l'
)
也可以使用subprocess模块
>> subprocess.call(
'ls -l'
.
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给出当前平台使用的行终止符。
例如,Windows使用'\r\n',Linux使用'\n'而Mac使用'\r'os.name指示你正在使用的平台。
比如对于Windows,它是'nt',而对于Linux/Unix用户,它是'posix'。
sys模块
sys
模块包含系统对应的功能。
1. sys.argv
包含命令行参数,
sys.argv[0]是
当前运行的程序名称
输出:
2. sys.exit
退出正在运行的程序。和以往一样,你可以看一下help(sys.exit)来了解更多详情。
3. sys.stdin、sys.stdout和sys.stderr
它们分别对应你的程序的标准输入、标准输出和标准错误流。
数据结构
Tools for Working with Lists 里面介绍了collections.deque,bisect和heapq,都是很有用的数据结构
其他
这里的介绍相当有限,详细的可以查阅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
0 0
- 简明python教程 --C++程序员的视角(八):标准库
- 简明python教程 --C++程序员的视角(三):模块
- 简明python教程 --C++程序员的视角(七):异常
- 简明python教程 --C++程序员的视角(五):面向对象的编程
- 简明python教程 --C++程序员的视角(二):函数及作用域
- 简明python教程 --C++程序员的视角(六):输入输出IO
- 简明python教程 --C++程序员的视角(四):容器类型(字符串、元组、列表、字典)和参考
- 简明python教程 --C++程序员的视角(一):数值类型、字符串、运算符和控制流
- 简明python教程 --C++程序员的视角(九):函数式编程、特殊类方法、测试及其他
- 简明Python教程 --- 14.Python标准库
- 简明python教程学习笔记(八)-元组
- 简明C语言教程(八)printf 用法
- 「学习笔记——Python」Python标准库简明教程
- 「学习笔记——Python」Python标准库简明教程II
- 简明Python3教程 16.标准库
- 简明Python3教程 16.标准库
- 简明Python教程(中文版)
- 简明Python教程(笔记)
- nginx和word和groovy的关联
- ios接入微信sdk
- c++和maven和c++的关联
- jre和mysql和jak的关联
- PHP Cookies
- 简明python教程 --C++程序员的视角(八):标准库
- NFS文件系统,导致板子ftp用不了情况
- 拖拽 DIV 效果
- Android逆向分析基础-反破解技术
- c++和jboss和mangodb的关联
- (原创文章)羊毛党何去何从
- dos和shell和python的关联
- Java编程规范
- 简明python教程 --C++程序员的视角(九):函数式编程、特殊类方法、测试及其他