python-2to3

How are you planning on handling the migration to Python 3?

放肆的年华 提交于 2019-11-27 00:33:25
问题 I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction: Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's finished? Have you already started or plan on starting soon? Or do you plan on waiting until the final version comes out to get into full swing? 回答1: Here's the general plan for Twisted. I was

Python 2 and Python 3 dual development

一曲冷凌霜 提交于 2019-11-26 20:30:40
I'm just starting a new Python project, and ideally I'd like to offer Python 2 and 3 support from the start, with minimal developmental overhead. My question is, what is the best way of doing this for brand new projects? I have come across projects that run 2to3, or even 3to2, as part of their installation script. This seems to be a very common way. However, there seems to be several different ways of doing this. I also came across Distribute . There is also the option of trying to write polyglot Python 2/Python 3 code. Even though this seems like a horrible idea, I have noticed that I tend to

Sorting list by an attribute that can be None

一世执手 提交于 2019-11-26 16:50:04
问题 I'm trying to sort a list of objects using my_list.sort(key=operator.attrgetter(attr_name)) but if any of the list items has attr = None instead of attr = 'whatever' , then I get a TypeError: unorderable types: NoneType() < str() In Py2 it wasn't a problem. How do I handle this in Py3? 回答1: The ordering comparison operators are stricter about types in Python 3, as described here: The ordering comparison operators (<, <=, >=, >) raise a TypeError exception when the operands don’t have a

Unpickling a python 2 object with python 3

不羁岁月 提交于 2019-11-26 11:15:01
I'm wondering if there is a way to load an object that was pickled in Python 2.4, with Python 3.4. I've been running 2to3 on a large amount of company legacy code to get it up to date. Having done this, when running the file I get the following error: File "H:\fixers - 3.4\addressfixer - 3.4\trunk\lib\address\address_generic.py" , line 382, in read_ref_files d = pickle.load(open(mshelffile, 'rb')) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1: ordinal not in range(128) Looking at the pickled object in contention, it's a dict in a dict , containing keys and values of

Unpickling a python 2 object with python 3

冷暖自知 提交于 2019-11-26 02:52:35
问题 I\'m wondering if there is a way to load an object that was pickled in Python 2.4, with Python 3.4. I\'ve been running 2to3 on a large amount of company legacy code to get it up to date. Having done this, when running the file I get the following error: File \"H:\\fixers - 3.4\\addressfixer - 3.4\\trunk\\lib\\address\\address_generic.py\" , line 382, in read_ref_files d = pickle.load(open(mshelffile, \'rb\')) UnicodeDecodeError: \'ascii\' codec can\'t decode byte 0xe2 in position 1: ordinal