PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/whats-new.html

https://bitbucket.org/dipyzh/dipyzh.bitbucket.org
HTML | 51 lines | 37 code | 14 blank | 0 comment | 0 complexity | 03f5d0cfedfe36619f577de4093d2a10 MD5 | raw file
  1. <!DOCTYPE html>
  2. <meta charset=utf-8>
  3. <title>深入 Python 3有何新内容</title><!--[if IE]><script src=j/html5.js></script><![endif]-->
  4. <link rel=stylesheet href=dip3.css>
  5. <style>
  6. body{counter-reset:h1 -1}
  7. h3:before{content:''}
  8. </style>
  9. <link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
  10. <link rel=stylesheet media=print href=print.css>
  11. <meta name=viewport content='initial-scale=1.0'>
  12. <form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8>&nbsp;<input type=search name=q size=25 placeholder="powered by Google&trade;">&nbsp;<input type=submit name=sa value=搜索></div></form>
  13. <p>当前位置: <a href=index.html>首页</a> <span class=u></span> <a href=table-of-contents.html#whats-new>深入 Python 3</a> <span class=u></span>
  14. <h1>深入 Python 3中有何新内容</h1>
  15. <blockquote class=q>
  16. <p><span class=u></span> Isnt this where we came in?<span class=u></span><br> Pink Floyd, The Wall
  17. </blockquote>
  18. <p id=toc>&nbsp;
  19. <h2 id=divingin><i>又名</i> 负号层</h2>
  20. <p class=f>读过之前的 <a href=http://diveintopython.org/>《深入 Python》</a>,甚至购买了印刷版?(多谢!)已经相当了解 Python 2 了?已经准备好投身 Python 3 之旅了?…… 如果这些假设都成立,请继续往下阅读。(如果哪条也不满足,最好还是 <a href=installing-python.html>从头开始</a> 吧。)
  21. <p>Python 3 提供了一段名为 <code>2to3</code> 的脚本希望你能学习它喜欢它并使用它<a href=porting-code-to-python-3-with-2to3.html>使用 <code>2to3</code> 将代码移植到 Python 3</a>一章是份参考手册涵盖了 <code>2to3</code> 工具能够自动调整的所有内容由于大量的修正内容都是语法变化因此如果想了解 Python 3 的语法变化这将会是个好的切入点<code>print</code> 现在变成了函数<code>`x`</code> 不再有效<i class=baa></i>诸如此类
  22. <p><a href=case-study-porting-chardet-to-python-3.html>案例分析移植 <code>chardet</code> Python 3 </a>全程记录了我将一个不寻常的类库从 Python 2 移植到 Python 3 的努力极其成功它或许能对你有帮助但由于必须首先对该类库有所了解然后才能理解为啥出问题以及我是如何修正的学习曲线会因此而相当陡峭许多问题的出现都与字符串密切相关说起这一点
  23. <p>字符串从哪儿说起呢Python 2 中有 strings Unicode stringsPython 3 中有 bytes strings也就是说现在所有字符串都是 Unicode 字符串那么如果要处理一堆字节应当使用新的 bytes 类型Python 3 <em></em>不会在 strings bytes 之间进行隐式转换因此无论何时如果无法确定该使用哪种类型你所写代码将毋庸置疑地出现问题请阅读 <a href=strings.html>字符串</a> 一章了解更多细节
  24. <p>整本书中Bytes strings 的对比将会一次又一次的反复出现
  25. <ul>
  26. <li><a href=files.html>文件</a>这一章中你将了解到以二进制模式和文本模式读取文件的区别以文本模式读取以及写入文件需要提供 <code>encoding</code> 参数文本文件的某些方法按字符计数但另一些方法却按照字节计数如果代码中假定一个字符等于一个字节在处理多字节字符时 <em>必将</em> 导致问题出现
  27. </li><li> <a href=http-web-services.html><abbr>HTTP</abbr> Web Services</a> 这一章中<code>httplib2</code> 模块通过 <abbr>HTTP</abbr> 获取 header 和数据<abbr>http</abbr> header 以字符串形式返回 <abbr>http</abbr> body 则以字节方式返回
  28. </li><li><a href=serializing.html>序列化 Python 对象</a>这一章中你将了解到 Python 3 pickle 模块为何要定义了一个与 Python 2 不向后兼容的新数据类型提示正是因为字节和字符串 与此同时<abbr>json</abbr> 也根本不支持 <code>bytes</code> 类型而我将展示解决这一难题的方法
  29. </li><li> <a href=case-study-porting-chardet-to-python-3.html>案例分析移植 <code>chardet</code> Python 3</a>这章中到处充斥着大段的关于 bytes strings 的讨论
  30. </li></ul>
  31. <p>就算从不关心 Unicode 但实际上不可能你也会想读一读 <a href=strings.html#formatting-strings>Python 3 的字符串格式</a>一节的相关内容它和 Python 2 里面的格式完全不同
  32. <p>迭代器在 Python 3 中无处不在和五年前撰写深入Python时相比我现在对它们的了解可是要深多了你也应该掌握它们因为过去在 Python 2 中返回列表的很多函数目前在 Python 3 里面返回的都是迭代器
  33. 至少你应该读一读 <a href=iterators.html#a-fibonacci-iterator>迭代器一章的后半部分</a> 以及 <a href=advanced-iterators.html#generator-expressions>高级迭代器一章的后半部分</a>
  34. <p>应广大群众要求我已经添加了一份关于<a href=special-method-names.html>特殊方法名称</a>的附录<a href=http://www.python.org/doc/3.1/reference/datamodel.html#special-method-names>Python 文档的 《数据模型》一节</a>类似,但是包含更多的“怪物”。
  35. <p>在我撰写深入 Python所有可用的 XML 类库都比较糟糕然后 Fredrik Lundh 编写了<a href=http://effbot.org/zone/element-index.htm> ElementTree </a>,这类库可就好得多了。Python 专家们很明智地<a href=http://docs.python.org/3.1/library/xml.etree.elementtree.html>将 ElementTree 吸纳为标准库的一部分</a>,现在它构成了我新撰写<a href=xml.html>《XML》</a>一章的基础。XML 的旧式解析方法仍然可用,但是你应该避免使用,因为它们的确很糟糕!
  36. <p>此外 Python 界还出现了一些新生事物不是语言方面的而是社区方面出现了像 <a href=http://pypi.python.org/>Python 软件包大全</a>(Python Package Index,PyPI) 这样的代码仓库。Python 提供了一些实用工具,可用于将代码打包成标准格式并分发到 PyPI 中。请阅读<a href=packaging.html>《将 Python 类库打包》</a>一章了解更多详细信息。
  37. <p class=c>© 20019 <a href=about.html>Mark Pilgrim</a>