python 教程 第十二章、 标准库
第十二章、 标准库
See Python Manuals ? The Python Standard Library ?
1) sys模块
import sys
if len(sys.argv) < 2:
print 'No action specified.'
sys.exit()
if sys.argv[1].startswith('--'):
option = sys.argv[1][2:]
if option == 'version':
print 'Version 1.2'
elif option == 'help':
print 'This program prints help'
else:
print 'Unknown option.'
sys.exit()
探索更多知识可使用help(sys)
2) os模块
os.name字符串指示你正在使用的平台。
os.getcwd()得到当前工作目录
os.getenv()和os.putenv()分别读取和设置环境变量。
os.listdir()返回指定目录下的所有文件和目录名。
os.remove()函数用来删除一个文件。
os.system()函数用来运行shell命令。
os.linesep字符串给出当前平台使用的行终止符
os.path.split()函数返回一个路径的目录名和文件名。
os.path.isfile()和os.path.isdir()函数分别检验给出的路径是一个文件还是目录。
os.path.existe()函数用来检验给出的路径是否真地存在。
探索更多知识可使用help(os)
3) 数学运算
Math模块
import math
print math.pi
print math.sqrt(9)
print sin(2 * pi / 180)
random模块
import random
print random.random()
print random.choice(['Life of Brian', 'Holy Grail'])
print random.randint(1, 10)
decimal小数
>>> import decimal # Decimals: fixed precision
>>> d = decimal.Decimal('3.141')
>>> d + 1 #Decimal('4.141')
>>> decimal.getcontext().prec = 2
>>> decimal.Decimal('1.00') / decimal.Decimal('3.00')
Decimal('0.33')
fractions分数
import fractions
f = fractions.Fraction(2, 3) #2/3
print f + 1 #5/3
print f + fractions.Fraction(1, 2) #7/6
python 教程 第十二章、 标准库的更多相关文章
- python 教程 第二十二章、 其它应用
第二十二章. 其它应用 1) Web服务 ##代码 s 000063.SZ ##开盘 o 26.60 ##最高 h 27.05 ##最低 g 26.52 ##最新 l1 26.66 ##涨跌 c ...
- python3 第三十二章 - 标准库概览
1. 操作系统接口 os 模块提供很多函数与操作系统进行交互︰ >>> import os >>> os.getcwd() # 返回当前的工作目录 'C:\\Pyt ...
- 进击的Python【第十二章】:mysql介绍与简单操作,sqlachemy介绍与简单应用
进击的Python[第十二章]:mysql介绍与简单操作,sqlachemy介绍与简单应用 一.数据库介绍 什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,每个数 ...
- Gradle 1.12用户指南翻译——第二十二章. 标准的 Gradle 插件
其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...
- 2017.2.13 开涛shiro教程-第十二章-与Spring集成(二)shiro权限注解
原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第十二章-与Spring集成(二)shiro权限注解 shiro注 ...
- 2017.2.13 开涛shiro教程-第十二章-与Spring集成(一)配置文件详解
原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第十二章-与Spring集成(一)配置文件详解 1.pom.xml ...
- Flask 教程 第十二章:日期和时间
本文翻译自The Flask Mega-Tutorial Part XII: Dates and Times 这是Flask Mega-Tutorial系列的第十二部分,我将告诉你如何以适配所有用户的 ...
- Flask 教程 第二十二章:后台作业
本文翻译自The Flask Mega-Tutorial Part XXII: Background Jobs 这是Flask Mega-Tutorial系列的第二十二部分,我将告诉你如何创建独立于W ...
- python 教程 第十五章、 结构布局
第十五章. 结构布局 #!/usr/bin/env python #(1)起始行 "this is a module" #(2)模块文档 import sys #(3)模块导入 d ...
随机推荐
- [Angular] Show a loading indicator in Angular using *ngIf/else, the as keyword and the async pipe
The network may be unreliable and loading data may take time. Thus it is important to give the user ...
- LDAP Browser/Editor v2.8.2
https://www.netiq.com/communities/cool-solutions/wp-content/uploads/sites/2/2009/07/Gawor_ldapbrowse ...
- Vue.js开发环境搭建的介绍
包含了最基础的Vue.js的框架,包含了打包工具和测试工具,开发调试的最基本的服务器,不需要关注细节,只需关注Vuejs对项目的实现 npm在国内的网络使用较慢,所以推荐下载安装淘宝的镜像 1: 2: ...
- [JS Compose] 1. Refactor imperative code to a single composed expression using Box
After understanding how Box is, then we are going to see how to use Box to refacotr code, to un-nest ...
- 终端中经常使用的shell 命令
Mac 在shell命令终端中,Ctrl+n相当于方向向下的方向键,Ctrl+p相当于方向向上的方向键. 在命令终端中通过它们或者方向键能够实现对历史命令的高速查找.这也是高速输入命令的技巧. 在命令 ...
- 利用C#与AE调用GP工具
转自原文 利用C#与AE调用GP工具 第一,首先要明确自己需要调用arctoolbox里面的什么工具,实现什么样的功能. 第三,编写command或tool工具,编写自己要的功能工具. 1)首先创建一 ...
- [Docker] Accessing a Container
If you want to get into container and look around, you can use: docker container exec to run against ...
- Linux下 kprobe工具的使用
此处转载: 一.Kprobe简单介绍 kprobe是一个动态地收集调试和性能信息的工具,它从Dprobe项目派生而来,是一种非破坏性工具,用户用它差点儿能够跟踪不论什么函数或被运行的指令以及一些异步事 ...
- js获取滚动条的宽度
function getScrollWidth() { var noScroll, scroll, oDiv = document.createElement("DIV"); oD ...
- [CSS Flex] Justify-content
justify content contol how element inside flex box align, it can be "right / end", or &quo ...