天天看點

python資料結構

<a href="http://blog.chinaunix.net/u2/84280/showart_1793926.html">http://blog.chinaunix.net/u2/84280/showart_1793926.html</a>

<a href="http://www.ibm.com/developerworks/cn/linux/l-pyint/index1.html">http://www.ibm.com/developerworks/cn/linux/l-pyint/index1.html</a>

資料結構

清單

a = ['1', 'cnbird', 'fuckyou']

取得值a[0]

元組

('wolf', 'elephant', 'penguin')

字典

{

 'key' : 'value',

 'key1': 'value'

}

鍵值的關系

序列 切片

shoplist[1:3]傳回從位置1開始,包括位置2,但是停止在位置3的一個序列切片,是以傳回一個含有兩個項目的切片。

startwith方法是用來測試字元串是否以給定字元串開始。<code>in</code>操作符用來檢驗一個給定字元串是否為另一個字元串的一部分。

<code>find</code>方法用來找出給定字元串在另一個字元串中的位置,或者傳回-1以表示找不到子字元串。<code>str</code>類也有以一個作為分隔符的字元串<code>join</code>序列的項目的整潔的方法,它傳回一個生成的大字元串。

時間函數:

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.

%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.

<a href="http://docs.python.org/library/time.html">http://docs.python.org/library/time.html</a>

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位元組。