python-2to3

RefactoringTool: ParseError: bad input: type=22, value='='

RefactoringTool: ParseError: bad input: type=22, value='=' Question: I’m refactoring some python2 code and changing it to python3 using 2to3 module. I’ve received following parse error: RefactoringTool: There was 1 error: RefactoringTool: Can’t parse ./helpers/repo.py: ParseError: bad input: type=22, value=’=’, context=(‘ ‘, (45, 25)) Here is a code that yields the error: except ImportError as error_msg: …

Total answers: 4

Unpickling a python 2 object with python 3

Unpickling a python 2 object with python 3 Question: 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 …

Total answers: 2

How to use 2to3 properly for python?

How to use 2to3 properly for python? Question: I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it. Asked By: GhostFrag1 || Source Answers: Install the following module which adds the …

Total answers: 9

Why does Python 3 need dict.items to be wrapped with list()?

Why does Python 3 need dict.items to be wrapped with list()? Question: I’m using Python 3. I’ve just installed a Python IDE and I am curious about the following code warning: features = { … } for k, v in features.items(): print(“%s=%s” % (k, v)) Warning is: “For Python3 support should look like … list(features.items()) …

Total answers: 5

Sorting list by an attribute that can be None

Sorting list by an attribute that can be None Question: 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 …

Total answers: 5

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

How are you planning on handling the migration to Python 3? Question: 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 …

Total answers: 7