[Tutor] 1.5.2 to 2.x.x upgrade question

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 16 Sep 2002 23:29:39 -0700 (PDT)


On Tue, 17 Sep 2002, Kirk Bailey wrote:

> If I can upgrade critter to2.foo, will I have to rewrite a bunch of
> scripts, or will all the scripts working now continue to operate
> correctly under the new version?

Ideally, the code should be portable from 1.52 to 2.2.1.  Realistically,
you might run into a small snag or two, but nothing too major.  *grin*



One of the "major" changes was to the list.append() method, where in old
version of Python, if we gave append() multiple arguments, it would work
with it:

###
bash-2.04$ python
Python 1.5.2 (#1, Apr 13 2000, 18:18:10)  [GCC 2.95.1 19990816 (release)]
on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> l = []
>>> l.append(1,2,3)
>>> l
[(1, 2, 3)]
>>>

This example shows that Python 1.52 would append the tuple object (1,2,3)
into our list.  But this is a little weird, because then we have two ways
of doing the same thing:

    l.append( (1, 2, 3) )

or:

    l.append(1, 2, 3)

To fix what appears to be a bug, Python 2 opts to make the second form of
append() here obsolete with an error message:

###
dyoo@coffeetable:~$ python
Python 2.2.1 (#2, Sep  7 2002, 15:35:22)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> l = []
>>> l.append(1,2,3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: append() takes exactly one argument (3 given)
###

I think that was the major compatibility change there;  the majority of
the other changes have been additional features (like list comprehenions),
or improvements in the standard library (like the addition of the
'difflib' difference-seeking module).  For the most part, code written for
1.52 should be upwards compatible to the Python 2 series.


But, of course, this is reality, so something's bound to go awry.  *grin*


If you run into any weirdness while switching over to the new version of
Python, post your script, and we can see what version-specific problems
there are.


Good luck!