RSS获取点

学习Python第四版(三)

即上一次更新隔了1个多礼拜。公司里项目跟进一时就没了时间,所以只好暂缓两天。今天将继续前言部分,并给前言一个结尾。还要给出一个说明,因为learning python的第三版的中文版已有成书,在这里获得,所以四版和三版的重复内容我将略过内容,不予以翻译,。但是如果有修订和更改,我将会特别得指出,并指明在3版中文版的页码,对应于4版原版的位置。

翻译者:Banumgoogle

前言(续)

3.0中被移除的部分

In addition to extensions, a number of language tools have been removed in 3.0 in an effort to clean up its design. Table P-2 summarizes the changes that impact this book, covered in various chapters of this edition. Many of the removals listed in Table P-2 have direct replacements, some of which are also available in 2.6 to support future migration to 3.0.

除了上文提到的扩展,有一些语言工具在3.0中被移除了,这样做是为了使架构更加清晰。这些改变将在表P-2中叙述,他们将覆盖这个版本的若干章节。有一些被移除的特性被直接替换了,还有一部分其实在2.6中已经提供了支持以方便未来向3.0迁移。

表P-2. 这本书涉及的3.0中的移除内容
移除内容 替换内容 覆盖的章节
reload(M) imp.reload(M) (or exec) 3, 22
apply(f, ps, ks) f(*ps, **ks) 18
`X` repr(X) 5
X <> Y X != Y 5
long int 5
9999L 9999 5
D.has_key(K) K in D (或者 D.get(key) != None) 8
raw_input input 3, 10
old input eval(input()) 3
xrange range 14
file open (以及 io 模型类库) 9
X.next X.__next__, 通过next(X)调用 14, 20, 29
X.__getslice__ X.__getitem__ 接受一个slice对象 7, 29
X.__setslice__ X.__setitem__ 接受一个slice对象 7, 29
reduce functools.reduce (或者使用循环语句) 14, 19
execfile(filename) exec(open(filename).read()) 3
exec open(filename) exec(open(filename).read()) 3
0777 0o777 5
print x, y print(x, y) 11
print >> F, x, y print(x, y, file=F) 11
print x, y, print(x, y, end=’ ‘) 11
u’ccc’ ‘ccc’ 7, 36
‘bbb’ for byte strings b’bbb’ 7, 9, 36
raise E, V raise E(V) 32, 33, 34
except E, X: except E as X: 32, 33, 34
def f((a, b)): def f(x): (a, b) = x 11, 18, 20
file.xreadlines for line in file: (或者X=iter(file)) 13, 14
D.keys()之类作为lists返回 list(D.keys()) (字典视图) 8, 14
map(), range(), 等作为lists返回 list(map()), list(range()) (内置) 14
map(None, …) zip (或者手动编码来 pad 结果) 13, 20
X=D.keys(); X.sort() sorted(D) (或者list(D.keys())) 4, 8, 14
cmp(x, y) (x > y) – (x < y) 29
X.__cmp__(y) __lt__, __gt__, __eq__,等 29
X.__nonzero__ X.__bool__ 29
X.__hex__, X.__oct__ X._index__ 29
Sort comparison functions 使用 key=transform 或 reverse=True 8
Dictionary <, >, <=, >= Compare sorted(D.items()) (或者使用循环) 8, 9
types.ListType list (types只针对于nonbuilt-in names) 9
__metaclass__ = M class C(metaclass=M): 28, 31, 39
__builtin__ builtins (改名) 17
Tkinter tkinter (改名) 18, 19, 24, 29, 30
sys.exc_type, exc_value sys.exc_info()[0], [1] 34, 35
function.func_code function.__code__ 19, 38
__getattr__ 以内置方式运行 在wrapper类中重新定义了__X__方法 30, 37, 38
-t, –tt 命令行替换 不正确的tab和空间使用总是返回一个错误 10, 12
from … *, within a function 可能只在文件的高层出现 22
import mod, in same package from . import mod, package-relative form 23
class MyException: class MyException(Exception): 34
异常模块(exceptions module) Built-in scope, library manual 34
thread, Queue modules _thread, queue (都被重命名了) 17
cPickle module _pickle (重命名了, 自动使用) 9
os.popen2/3/4 subprocess.Popen (os.popen保留) 14
基于字符串的错误 基于类的错误 (这点在2.6中已经被要求) 32, 33, 34
字符模块函数 字符对象方法 7
未绑定的方法 Functions(通过instance来调用静态方法) 30, 31
混合类型的比较和排序 非数字的混合类型比较会抛出错误 5, 9

There are additional changes in Python 3.0 that are not listed in this table, simply because they don’t affect this book. Changes in the standard library, for instance, might have a larger impact on applications-focused books like Programming Python than they do here; although most standard library functionality is still present, Python 3.0 takes further liberties with renaming modules, grouping them into packages, and so on. For a more comprehensive list of changes in 3.0, see the “What’s New in Python 3.0” document in Python’s standard manual set.

Python3.0中的其他一些变化没有在表中列出,因为它们对我们这本书没有影响。比如说,标准库中的一些变化,可能对面向于应用开发的书影响比较大,虽然大多数的标准库依然运作良好,Python3.0将在重命名、打包模块等方面拥有更多的自由。如果你想获取3.0中改变的进一步信息,请参阅Python标准手册中的”What’s New in Python 3.0″文档。

If you are migrating from Python 2.X to Python 3.X, be sure to also see the 2to3 automatic code conversion script that is available with Python 3.0. It can’t translate everything, but it does a reasonable job of converting the majority of 2.X code to run under 3.X. As I write this, a new 3to2 back-conversion project is also underway to translate Python 3.X code to run in 2.X environments. Either tool may prove useful if you must maintain code for both Python lines; see the Web for details.

如果你正从2.X版本迁移到3.X版本,请确保看看2to3自动代码转化脚本,这个脚本在Python3.0下可用。它不能翻译所有一切,但是可以让2.X中大多数的代码运行在3.X下。我写这本书的时候,新的3to2转化项目也在进行之中,目的在于转化3.X代码使它们能够运行在2.6环境下。两个工具也许能够在你必须维护两套Python版本时给与帮助。

Because this fourth edition is mostly a fairly straightforward update for 3.0 with a handful of new chapters, and because it’s only been two years since the prior edition was published, the rest of this Preface is taken from the prior edition with only minor updating.

因为第四版主要是对于3.0的更新提供新的少量章节,同时也因为离上一版出版才两年的时间,前言的剩下部分将从前一个版本中直接拿过来,只有极少量的更新。(译者注:剩下部分请参阅3版中文)

"学习Python第四版(三)"by banum2010-8-13 at 4:02 下午no CommentsTags:

没有评论 »

还没有评论呢。

这篇文章上的评论的 RSS feed TrackBack URL

留下评论

Powered by WordPress