python数据结构
2009-08-01 21:17
169 查看
http://blog.chinaunix.net/u2/84280/showart_1793926.html
http://www.ibm.com/developerworks/cn/linux/l-pyint/index1.html
数据结构
列表
a = ['1', 'cnbird', 'fuckyou']
取得值a[0]
元组
('wolf', 'elephant', 'penguin')
字典
{
'key' : 'value',
'key1': 'value'
}
键值的关系
序列 切片
shoplist[1:3]返回从位置1开始,包括位置2,但是停止在位置3的一个序列切片,因此返回一个含有两个项目的切片。
startwith方法是用来测试字符串是否以给定字符串开始。
时间函数:
time.strftime(format[, t])
http://docs.python.org/library/time.html
Python pty
使用平台IRIX,Linux
冒充终端模块
此模块包括了三个函数
Pty模块定义操控冒充终端概念的具体实现,开启另外一个进程同时对于来自终端控制台进行写和读。
有下面三个函数
pty.fork()
fork作为伪终端连接到子进程的控制终端.返回值是(pid, fd).注意这个子进程的pid如果是0那么fd失效。父进程返回了子进程的pid值,同时fd是一个连接到子进程控制终端的文件描述符。
pty.openpty()
使用pty.openpty开一个新的伪终端。返回值是相同的文件描述符(master, slave)
pty.spawn(argv[,master_read[,stdin_read]])
产生一个新的进程同时作为当前进程标准IO连接到它的控制终端。这个经常被用作必须要求读控制终端的程序。例如SSH等
master_read和stdin_read函数是从文件描述符中读,当它被调用的时候默认是尝试读取1024字节。
http://www.ibm.com/developerworks/cn/linux/l-pyint/index1.html
数据结构
列表
a = ['1', 'cnbird', 'fuckyou']
取得值a[0]
元组
('wolf', 'elephant', 'penguin')
字典
{
'key' : 'value',
'key1': 'value'
}
键值的关系
序列 切片
shoplist[1:3]返回从位置1开始,包括位置2,但是停止在位置3的一个序列切片,因此返回一个含有两个项目的切片。
startwith方法是用来测试字符串是否以给定字符串开始。
in操作符用来检验一个给定字符串是否为另一个字符串的一部分。
find方法用来找出给定字符串在另一个字符串中的位置,或者返回-1以表示找不到子字符串。
str类也有以一个作为分隔符的字符串
join序列的项目的整洁的方法,它返回一个生成的大字符串。
时间函数:
time.strftime(format[, t])
Directive | Meaning | Notes |
---|---|---|
%a | Locale’s abbreviated weekday name. | |
%A | Locale’s full weekday name. | |
%b | Locale’s abbreviated month name. | |
%B | Locale’s full month name. | |
%c | Locale’s appropriate date and time representation. | |
%d | Day of the month as a decimal number [01,31]. | |
%H | Hour (24-hour clock) as a decimal number [00,23]. | |
%I | Hour (12-hour clock) as a decimal number [01,12]. | |
%j | Day of the year as a decimal number [001,366]. | |
%m | Month as a decimal number [01,12]. | |
%M | Minute as a decimal number [00,59]. | |
%p | Locale’s equivalent of either AM or PM. | (1) |
%S | Second as a decimal number [00,61]. | (2) |
%U | Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0. | (3) |
%w | Weekday as a decimal number [0(Sunday),6]. | |
%W | Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. | (3) |
%x | Locale’s appropriate date representation. | |
%X | Locale’s appropriate time representation. | |
%y | Year without century as a decimal number [00,99]. | |
%Y | Year with century as a decimal number. | |
%Z | Time zone name (no characters if no time zone exists). | |
%% | A literal '%' character. |
http://docs.python.org/library/time.html
Python pty
使用平台IRIX,Linux
冒充终端模块
此模块包括了三个函数
Pty模块定义操控冒充终端概念的具体实现,开启另外一个进程同时对于来自终端控制台进行写和读。
有下面三个函数
pty.fork()
fork作为伪终端连接到子进程的控制终端.返回值是(pid, fd).注意这个子进程的pid如果是0那么fd失效。父进程返回了子进程的pid值,同时fd是一个连接到子进程控制终端的文件描述符。
pty.openpty()
使用pty.openpty开一个新的伪终端。返回值是相同的文件描述符(master, slave)
pty.spawn(argv[,master_read[,stdin_read]])
产生一个新的进程同时作为当前进程标准IO连接到它的控制终端。这个经常被用作必须要求读控制终端的程序。例如SSH等
master_read和stdin_read函数是从文件描述符中读,当它被调用的时候默认是尝试读取1024字节。
相关文章推荐
- Python笔记——几种数据结构的实现:栈、队列及二叉树
- Python数据结构之二叉树
- python数据结构之元组,列表,字典的函数
- 最长递增子序列_python_算法与数据结构
- python数据结构
- python 基于字节码分析数据结构是否线程安全
- Python数据结构之实现队列
- python数据结构与算法 1 基本数据结构
- Python数据结构之序列
- [从头学数学] 第253节 Python实现数据结构:比特集(BitSet)
- python数据结构,二分查找法的实现!
- Python数据结构——队列
- Python新手学习基础之数据结构-序列2
- 基于Python检索系统(3)分词后建立数据结构
- Python数据结构——树的实现
- Python 教程阅读笔记(四):数据结构
- Python数据结构之链表
- Python数据结构之图与二叉查找树
- python中的数据结构整理
- Python中的高级数据结构