非常方便,google了下,方法如下:
Under the kde environment in RedHat, it's easy to open terminal everywhere by rightclick. Here is the method to add this feature to your ubuntu:
##CONTINUE##
sudo apt-get install nautilus-open-terminal
sudo apt-get install nautilus-open-terminal

>>> import time >>> t1 = time.localtime() >>> t1 time.struct_time(tm_year=2009, tm_mon=4, tm_mday=20, tm_hour=20, tm_min=8, tm_sec=47, tm_wday=0, tm_yday=110, tm_isdst=1) >>> strFormat = "%Y-%m-%d %H:%M:%S" >>> t2 = time.strftime(strFormat) >>> t2 '2009-04-20 20:09:29'
%a Abbreviated weekday name %A Full weekday name %b Abbreviated month name %B Full month name %c Date and time representation appropriate for locale %d Day of month as decimal number (01 - 31) %H Hour in 24-hour format (00 - 23) %I Hour in 12-hour format (01 - 12) %j Day of year as decimal number (001 - 366) %m Month as decimal number (01 - 12) %M Minute as decimal number (00 - 59) %p Current locale's A.M./P.M. indicator for 12-hour clock %S Second as decimal number (00 - 59) %U Week of year as decimal number, with Sunday as first day of week (00 - 51) %w Weekday as decimal number (0 - 6; Sunday is 0) %W Week of year as decimal number, with Monday as first day of week (00 - 51) %x Date representation for current locale %X Time representation for current locale %y Year without century, as decimal number (00 - 99) %Y Year with century, as decimal number %z, %Z Time-zone name or abbreviation; no characters if time zone is unknown %% Percent sign
#!/usr/bin/python
#coding:utf-8
import datetime
import time
format="%Y-%m-%d %H:%M:%S"
t1=time.strptime("2008-01-31 00:11:23",format)
t2=datetime.datetime(t1[0],t1[1],t1[2],t1[3],t1[4],t1[5],t1[6])
t3=t2-datetime.timedelta(minutes=30)
t3=str(t3)
b1=t3[0:4]
b2=t3[5:7]
b3=t3[8:10]
b4=t3[11:13]
b5=t3[14:16]
b6=t3[-2:]
print b1
print b2
print b3
print b4
print b5
print b6
a="2009-02-15 21:00:08"
import re
s=re.split("\D*",a)
print s
import datetime,time
format="%Y-%m-%d %H:%M:%S"
result=datetime.datetime(*time.strptime("2008-01-31 00:11:23",format)[:6])-datetime.timedelta(minutes=30)
print result.strftime(format)
1. 定义: tuple用()或者直接用分号间隔开一系列元素, list用[], dict用{}
例如: t1=’a’, ‘haha’, 1, 3 或者 t2=(‘a’, ‘haha’,1, 3)
lst1=[‘a’,’haha’, 1, 3], dict1 = {1:’a’, 2:’haha’, 3:1, 4:3}
dict有特殊的构建方法,例如:
dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])或者
dict(sape=4139, guido=4127, jack=4098)
2. 操作: tuple一旦定义,不可改变其值; list和dict可以.list可以使用append方法添加元素, dict可直接添加,好像maping一样.
3. 引用: 都必须用[],但是tuple和list用id, dict则必须用键值/key才能索引.
4. 特殊的数据类型set: set([list])可以返回list中所有不重复元素
当queue使用时, 先入先出操作要用pop(0)这个方法; 当stack使用时,后入先出操作直接使用pop(), 不用指定index会默认return最后一个element.
>>> t = (1, 2, 3, 'a') >>> t (1, 2, 3, 'a') >>> for i in t: print i 1 2 3 a >>>
>>> t=(1,2,3) >>> len(t) 3 >>> t (1, 2, 3) >>> t[1] 2 >>> t[1] = 'a' Traceback (most recent call last): File "", line 1, in t[1] = 'a' TypeError: 'tuple' object does not support item assignment
>>> a = range(5) # generate a list from 0 to 4
>>> a
[0, 1, 2, 3, 4]
>>> a[2] # get the value of index 2
2
>>> a[3] = 'e'
>>> a
[0, 1, 2, 'e', 4]
>>> a[2:4] # slice, from index 2 to 4, excluding 4, like[2,4)
[2, 'e']
>>> a[:3] # slice, from start(0) to 3, excluding 3, like [0,3)
[0, 1, 2]
>>> a[2:] # slice, from index 2 to the end, like [2,len(a)-1]
[2, 'e', 4]
>>> a[:] # slice, whole list copy, this method does not return a new object
[0, 1, 2, 'e', 4]
>>> a.append('last') # append element to the end
>>> a
[0, 1, 2, 'e', 4, 'last']
>>> a.index('e') # return the index of 'e' of the first occurrence
3
>>> a.index('a') # return ValueError if 'a' is not in the list
Traceback (most recent call last):
File "", line 1, in
a.index('a')
ValueError: list.index(x): x not in list
>>> a.reverse() # reverse the list
>>> a
['last', 4, 'e', 2, 1, 0]
>>> a.remove('e') # remove the first element with specified value
>>> a
['last', 4, 2, 1, 0]
>>> del a[3] # remove an element in the specify position
>>> a
['last', 4, 2, 0]
>>> b = ['a','b','c']
>>> a.extend(b) # extend another list at the end of the current one
>>> a
['last', 4, 2, 0, 'a', 'b', 'c']
>>> a.insert(2,'new item') # insert an element into the list at the specify position
>>> a
['last', 4, 'new item', 2, 0, 'a', 'b', 'c']
>>> a+= [1,2] # use + oeration to concatenate lists
>>> a
['last', 4, 'new item', 2, 0, 'a', 'b', 'c', 1, 2]
>>> a.count(2) # count the number of 2 in the list
2
>>> a.pop() # return the last element and delete it from the list
2
>>> a.count(2)
1
>>> a
['last', 4, 'new item', 2, 0, 'a', 'b', 'c', 1]
>>> a.sort() # sort the list, there are some parameters can be found from the document
>>> a
[0, 1, 2, 4, 'a', 'b', 'c', 'last', 'new item']
>>> a
{'username': 'xenos', 'blog': 'http://52xenos.blogspot.com/', 'uid': 1} # new dict object
>>> a['username'] # return value according to the key 'username'
'xenos'
>>> a['username'] = 'daniel' # refine the value of the key 'username'
>>> if a.has_key('username'): # find if there is a pair "key:value" in the dict, if no, return Wrong
print a['username']
else:
print 'Wrong'
daniel
>>> a.get('username','Wrong') # same as the if...else... shown above
'daniel'
>>> a.keys() # return all keys in a list
['username', 'blog', 'uid']
>>> a.values() # return all values in a list
['daniel', 'http://52xenos.blogspot.com/', 1]
for condition: do something ... while condition: do something ...
for condition1: do something1 ... for condition2: do something2 ... for condition3: do something3 ... ... ... while condition1: do something1 ... while condition2: do something2 ... while condition3: do something3 ... ... ...
>>> a = range(4) >>> for i in a: print 'i= %d.' % i i= 0. i= 1. i= 2. i= 3. >>> i 3 >>> i=0 >>> while i in a: print 'i=%d.' % i i+=1 i=0. i=1. i=2. i=3. >>> j = 1000000 >>> j = 10000 >>> i = 1 >>> while i in xrange(j): print 'i=%d.' % i i+=1 i=1. i=2. i=3. i=4. i=5. ... i=9999.
if condition: do something1 else: do something2
if condition: do something1 else: do something2
>>> a = [0,1,2,3] >>> if i in a: print 'i is in a.' else: print 'i is not in a.' i is not in a.