您的位置:首页 > 理论基础 > 数据结构算法

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方法是用来测试字符串是否以给定字符串开始。
in
操作符用来检验一个给定字符串是否为另一个字符串的一部分。

find
方法用来找出给定字符串在另一个字符串中的位置,或者返回-1以表示找不到子字符串。
str
类也有以一个作为分隔符的字符串
join
序列的项目的整洁的方法,它返回一个生成的大字符串。

 

时间函数:

time.strftime(format[, t])

 

DirectiveMeaningNotes
%aLocale’s abbreviated weekday name. 
%ALocale’s full weekday name. 
%bLocale’s abbreviated month name. 
%BLocale’s full month name. 
%cLocale’s appropriate date and time representation. 
%dDay of the month as a decimal number [01,31]. 
%HHour (24-hour clock) as a decimal number [00,23]. 
%IHour (12-hour clock) as a decimal number [01,12]. 
%jDay of the year as a decimal number [001,366]. 
%mMonth as a decimal number [01,12]. 
%MMinute as a decimal number [00,59]. 
%pLocale’s equivalent of either AM or PM.(1)
%SSecond as a decimal number [00,61].(2)
%UWeek 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)
%wWeekday as a decimal number [0(Sunday),6]. 
%WWeek 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)
%xLocale’s appropriate date representation. 
%XLocale’s appropriate time representation. 
%yYear without century as a decimal number [00,99]. 
%YYear with century as a decimal number. 
%ZTime 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字节。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息