Re: Python 2.6
※ 引述《mythnc (迷小心)》之銘言:
: http://www.python.org/download/releases/2.6/
: 今天才剛剛開始看Python的入門書
: 剛剛好要找Python的資料看到的 ^^"
: 不知道要不要ubuntu內的Python 2.5.2升級到2.6 ?
: 2.6好像是到Python 3的過渡版本...
: 有人試過2.6了嗎?
2.6 拉了好幾個有用的新東西進來 ...
下面是 2.6 what's new 裡面我覺得對我來說比較有用的東西摘錄
用法跟 threading 很像的 multiprocessing module
新的字串格式化語法 (這個等好久了 O_Q)
>>> "User ID: {0}".format("root")
'User ID: root'
>>> import mimetypes
>>> 'Content-type: {0[.mp4]}'.format(mimetypes.types_map)
'Content-type: video/mp4'
>>> fmt = '{0:15} ${1:>6}'
>>> fmt.format('Registration', 35)
'Registration $ 35'
>>> fmt.format('Tutorial', 50)
'Tutorial $ 50'
>>> fmt.format('Banquet', 125)
'Banquet $ 125'
多用 as 關鍵字,更不容易混淆的 exception 語法
try:
....
except (TypeError, ValueError) as e:
....
簡化物件屬性程式碼,新的 @getter, @setter, @deleter decorator
class C(object):
@property
def x(self):
return self._x
@x.setter
def x(self, value):
self._x = value
@x.deleter
def x(self):
del self._x
class D(C):
@C.x.getter
def x(self):
return self._x * 2
@x.setter
def x(self, value):
self._x = value / 2
新的 I/O module, PYTHONIOENCODING 環境變數
Abstract Base Class (這個有沒有人要解說一下? XD)
不過我常拿來幹壞事的 new module 被 deprecate 了 ... 得看看要改用什麼作法 _A_
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.40.88
推
10/05 22:34, , 1F
10/05 22:34, 1F
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章