[Tutor] word_probles.py

Dave Angel davea at ieee.org
Sun Aug 8 22:00:47 CEST 2010

Shurui Liu wrote:
> Okay. I am using WinXP, Python 3.1 on my workstation. 
> And this is the Python version information I got from putty.exe: 
> Python 2.5.4 (r254:67916, Apr 13 2009, 18:09:11)
> [GCC 4.2.1 20070719  [FreeBSD]] on freebsd7
> <snip>
You cannot use the same python source on 2.5 as you do in 3.1, 
regardless of OS platform.  For just about any non-trivial program, the 
differences will get you compile errors on one or the other.

If you're targeting 2.5 on the remote machine, you'd better be 
developing/testing with 2.5 on your own.  You still might have OS 
differences, but they're more likely to be manageable.

For an example of a gross difference, look at print.

In 2.5, print is a statement, and takes particular syntax following the 
word print.

In 3.x, print() is a function, and must have a standard argument list.  
This means that some options that you might have used in 2.5 will just 
be syntax errors.  And conversely, it means the print function may be 
called inside an expression, which would be totally illegal on 2.5.  It 
is possible to build a string ahead of time, and enclose a single string 
in parentheses (effectively ignored on 2.5), and get something that 
works on both platforms.

Alternatively, there's the 2to3 converter, but that's a nuisance at 
best.  Useful for one-time conversion, and for those situations that 
absolutely must run on both platforms, but otherwise a pain to keep both 
versions of the source up to date.  And you'd still have to test with 
2.5 before deploying to an unsuspecting user.


More information about the Tutor mailing list