Supporting Python 3(支持Python 3)
- 关于本书
- 序
- 欢迎来到Python 3
- 迁移策略
- Preparing for Python 3
- Comparatively tricky
- Implementing __hash__()
- Run under Python 2.7.
- Use // instead of / when dividing integers
- Use new-style classes
- Separate binary data and strings
- When sorting, use key instead of cmp
- Use rich comparison operators
- Make sure you aren’t using any removed modules
- Testing coverage and tox
- Optional: Use the iterator-methods on dictionaries
- 2to3
- Running tests with Distribute
- Running 2to3 with Distribute
- Running 2to3 on install
- Explicit fixers
- Using 2to3
- Distributing packages
- Supporting multiple versions of Python with Distribute
- Common migration problems
- write() has a return value
- Types are now classes
- Handling expected exceptions
- String representation
- dict and set order
- Byte literals
- Binary data in Python 2 and Python 3
- Nicer solutions
- Manipulating binary data
- Reading from files
- Incorrect imports
- Relative import problems
- Unorderable types, __cmp__ and cmp
- Sorting
- Sorting Unicode
- Bytes, strings and Unicode
- Replacing UserDict
- CSV API changes
- Running doctests
- Improving your code with modern idioms
- Abstract base classes
- multiprocessing and futures
- numbers and fractions
- Use sorted() instead of .sort()
- Coding with context managers
- Advanced string formatting
- Class decorators
- Set literals
- yield to the generators
- More comprehensions
- The next next()
- New modules
- Supporting Python 2 and 3 without 2to3 conversion
- Supporting the print() function
- Handling exceptions
- Import errors
- Integer incompatibilities
- More bytes, strings and Unicode
- Two times three is “six”
- Migrating C extensions
- Extending 2to3 with your own fixers
- When fixers are necessary
- The Parse Tree
- Creating a fixer
- Modifying the Parse Tree
- Finding the nodes with Patterns
- Language differences and workarounds
- apply()
- buffer()
- callable()
- Classes
- Comparisons
- coerce() and __coerce__
- Dictionary methods
- except
- Exception objects
- exec
- execfile
- file
- filter()
- Imports
- Indentation
- input() and raw_input()
- Integer division
- long
- map()
- Metaclasses
- .next()
- Parameter unpacking
- raise
- range() and xrange()
- repr() as backticks.
- Rounding behavior
- Slice operator methods
- Sorting
- StandardError
- String types
- Reorganizations and renamings
时间: 2024-07-30 10:04:00