作者Tiberius (渴望平凡的幸福)
看板Python
标题Re: Python 2.6
时间Sun Oct 5 00:16:30 2008
※ 引述《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