regebro / supporting-python-3 Goto Github PK
View Code? Open in Web Editor NEWSupporting Python 3
Supporting Python 3
Your book, especially http://python3porting.com/cextensions.html, has already been very helpful to start porting rdiff-backup to Python3, but I'm stuck on the disappearance of Py_FindMethod as used in rdiff_backup/_librsyncmodule.c. According to my research:
So quite a lot of missing explanations, I think, which you could possibly highlight in an update.
"Supporting" is a better word than "Porting".
These are the things that I promised to do in the crowd funding campaign, https://github.com/regebro/supporting-python-3/issues/new
Currently the README.rst goes into great depth about pdf generation in a number of page layouts but does not mention the fact that the makefile includes targets for html, dirhtml and epub.
This gives the impression that only pdf output is available and that anybody looking for epub support is going to have to do it themselves.
Hi,
Can I copy one sample code from the book and use it in a commercial product?
The signed Funders Edition books are planned for PyCon.
2to3 is today only relevant if you still need to support both Python 2.5 and Python 3.2.
Perhaps a separate chapter?
The string sys.version
should not be used for version checks as there is no guarantee across implementations that the version number is at the beginning of the string. Instead sys.version_info
should be used which is a tuple of integers.
Section A.9 says that the issue with Exception objects that are not iterable and indexable is supported by 2to3.
But it seems that it doesn't. I tried the code presented as the example:
e = Exception('arg1', 'arg2')
e[1]
and found that it is not converted by 2to3. This fix is not mentioned neither in documentation, nor in the code of fix_except
fixer.
Maybe am I missing something?
Thanks for this guide, I've found it a really useful resource when porting some old Python 2 code ❤️
One thing I did notice: the round()
substitute given for Python 2-like behaviour in Python 3 is close, but fails to give the exact Python 2 behaviour in a few cases.
For example:
Python 2.7.18 (default, Jul 1 2022, 12:27:04)
[GCC 9.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> def my_round(x, d=0):
... p = 10 ** d
... if x > 0:
... return float(math.floor((x * p) + 0.5))/p
... else:
... return float(math.ceil((x * p) - 0.5))/p
...
>>> my_round(353.765, 2)
353.77
>>> round(353.765, 2)
353.76
Another implementation that I found seems to be a slight improvement. It is also tested against examples taken from the Python 2 test suite.
>>> round2(353.765, 2)
353.76
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.