Minor 2.0 incompatibility

Timothy Docker timd at macquarie.com.au
Tue Oct 24 02:49:36 EDT 2000


The following code works under 1.5.2 but not under 2.0...

 | import string
 | 
 | class A:
 |     fromString = string.atoi
 |     def go(self, s):
 |         print self.fromString(s)
 | 
 | a = A()
 | a.go( '10' )

giving output...

 | tcc2:timd $ /opt/python/python1.5.2/bin/python test.py
 | 10
 | tcc2:timd $ /opt/python/python2.0/bin/python test.py
 | Traceback (most recent call last):
 |   File "test.py", line 10, in ?
 |     a.go( '10' )
 |   File "test.py", line 6, in go
 |     print self.fromString(s)
 |   File "/opt/python/python2.0/lib/python2.0/string.py", line 215, in atoi
 |     return _int(s, base)
 | TypeError: an integer is required
 | tcc2:timd $ 

Presumably, defining assigning string.atoi directly to fromString is
dubious, and the following works ok...

 | import string
 | 
 | class A:
 |     def fromString(self, s): return  string.atoi(s)
 |     
 |     def go(self, s):
 |         print self.fromString(s)
 | 
 | a = A()
 | a.go( '10' )

It's an easy enough fix, once I worked out what to do. But what is
actually going on here? Something seems to have changed with the way
that atoi now works, and somehow it worked by fluke before. Either
way, the traceback is a bit cryptic.

Comments?

Tim
 



More information about the Python-list mailing list