It’s just data

2to3

As a learning exercise, I tried converting the Universal Feed Parser to Python 3.0.  I picked it because it is a relatively self contained code base that I am familiar with, one that is actively in use, and one that has seen the wear and tear of dealing with compatibility (and the need to monkeypatch the occasional bug) of a number of Python releases.

$ svn co http://svn.python.org/projects/sandbox/trunk/2to3/
$ cd 2to3

$ python refactor.py -w ../feedparser/feedparser.py > feedparser.2to3.diff
root: Generating grammar tables from /home/rubys/svn/2to3/PatternGrammar.txt
root: Writing grammar tables to /home/rubys/svn/2to3/PatternGrammar.pickle
../feedparser/feedparser.py: At line 3091: You should use a for loop here
RefactoringTool: Files that were modified:
RefactoringTool: ../feedparser/feedparser.py

$ python refactor.py -w ../feedparser/feedparsertest.py > feedparsertest.2to3.diff
RefactoringTool: Files that were modified:
RefactoringTool: ../feedparser/feedparsertest.py

A few manual changes later, and 91% of the tests pass.  I’m confident that with a little more work, I could quickly get that to 99%, perhaps even to 100%.

The Good

The Bad

The Ugly


Sam Ruby on python 3

[link]...

Excerpt from del.icio.us/tag/python at

Imperfection - Martin Jansen

Last Friday, Guido van Rossum released the first alpha version of Python 3.0 aka Python 3000 . Judging by the changelog , the Python developers got rid of a number of annoyances and inconsistencies in order to make the language more cleaner...

Excerpt from Planet PHP at

How would one do a <code>open(file).read()</code> where file is a non-unicode file in 3000?

Posted by Henrik Lied at

import codecs
codecs.open(file,'r',encoding).read()
Posted by Sam Ruby

at

I probably should mention that as ASCII is a proper subset of utf-8, open(file).read() will likely work for most of your test data and wait to fail until after you deploy, probably as a result of somebody copy/pasting so-called “smart quotes”.

Also, open(file,"rb").read() will return raw bytes.

Posted by Sam Ruby at

Sam Ruby: 2to3

Sam Ruby: 2to3 . Sam’s report on an attempt to port the Universal Feed Parser to Python 3.0. The 2to3 tool does most of the work, but it seems the unicode changes can be pretty tricky....

Excerpt from Simon Willison's Weblog at

Sam Ruby: 2to3

Sam Ruby: 2to3 . Sam’s report on an attempt to port the Universal Feed Parser to Python 3.0. The 2to3 tool does most of the work, but it seems the unicode changes can be pretty tricky....

Excerpt from PythonLovers.com at

Sam Ruby's report on porting the Universal Feed Parser to Python 3.0 using the 2to3 conversion tool

[link] [more]...

Excerpt from reddit.com: programming - newest submissions at

Sam Ruby: 2to3

Simon Willison : Sam Ruby: 2to3 - Sam Ruby: 2to3. Sam’s report on an attempt to port the Universal Feed Parser to Python 3.0. The 2to3 tool does most of the work, but it seems the unicode changes can be pretty tricky....

Excerpt from HotLinks - Level 1 at

La alpha 1 di Python 3000

Scopro dal blog di Guido van Rossum che ieri è stata rilasciata la 3.0a1 di Python – famoso e amato linguaggio di programmazione multiparadigma*. Su python.org (sito ufficiale) trovate la pagina della release. E’ inoltre disponibile...

Excerpt from Il Tao dei blog at

The one question that this exercise raised for me that I can’t seem to shake is this: what is the role of 2.6?

Sure, it’s about migration. The process description is such that all code shall be adapted in Python 2.6 with appropriate hints and none in Python 3.0. Together with these hints the conversion process shall become fully automized. I didn’t examine 2to3 yet and I’m not sure how the the user provides hints to the conversion tool. It might even be that Python 2.6 introduces new language syntax for this purpose only.

Posted by Kay Schluehr at

The process description is such that all code shall be adapted in Python 2.6 with appropriate hints and none in Python 3.0.

This works well for top level applications, but not so well for library developers for which the library is not part of Python itself.  Specifically, it would require a number of libraries I depend upon (e.g., httplib2, feedparser, html5lib) to stop supporting Python 2.5.

Posted by Sam Ruby at

4 Sep 2007

Sam Ruby tryied to port the Univesal Feed Parser to Py3k. 91% of the tests pass, what is quite nice. UFP is a great piece of code, and one of the first things I would miss. PyGTK people started talking about the migration - this will be very...

Excerpt from Advogato blog for eopadoan at

Sam Ruby's report on porting the Universal Feed Parser to Python 3.0 using the 2to3 conversion tool

[link] [comments]...

Excerpt from reddit.com: reddit.com: ネットデハッケン at

Porting feedparser to Python 3

Today I’m announcing I’m throwing my hat in the ring to port feedparser to Python 3. There’s a ticket open regarding this at the feedparser bug tracker, but the person who’s working on porting it appears to be writing Python 3 code instead of...

Excerpt from Kurt McKee at

Add your comment