[Tutor] [string.atoi_error, revisionism, and Python 1.0.2]
Tony Cappellini
tony at tcapp.com
Tue Mar 23 17:57:41 EST 2004
Thanks Danny.
This clears things up quite well.
On Mon, 22 Mar 2004, Danny Yoo wrote:
>
>
> On Mon, 22 Mar 2004, Tony Cappellini wrote:
>
> > > > I've found this code on the net- I think it was from the Python Cookbook.
> > >
> > > > try:
> > > > Celsius=float(string.atoi(CTemp))
> > > > except string.atoi_error:
> > > > print repr(CTemp), "not a numeric value"
> > > > else:
> > >
> > > This code is very outdated. Today with a recent python noone would
> > > write it like that.
>
> [some text cut]
>
> > What I don't understand is- when I looked in the Python documentation,
> > under exceptions, only the built-in exceptions were listed.
>
>
>
> Hi Tony,
>
> Yes, the built-in exceptions in:
>
> http://www.python.org/doc/lib/module-exceptions.html
>
> do not have string.atoi_error, nor is 'string.atoi_error' documented in
> the 'string' module.
>
> http://www.python.org/doc/lib/module-string.html
>
>
> Interesting. Let me check something:
>
>
> ###
> >>> import string
> >>> string.atoi_error
> <class exceptions.ValueError at 0x40071b0c>
> ###
>
> Ah! string.atoi_error is an alias for the standard exception ValueError!
>
>
>
> Ok, I think I have a theory of what's happening. Let's assume for the
> moment that that celsius-calculation code was written a long time ago,
> since it uses the deprecated 'string' module. We can go back to Python
> 1.52's library documentation:
>
> http://python.org/doc/1.5.2p2/lib/lib.html
>
Tony
More information about the Tutor
mailing list