Probably a stupid newbie question....i got to ask

Peter Hansen peter at engcorp.com
Wed Aug 8 22:17:19 EDT 2001


fett at tradersdata.com wrote:
> 
> How do you use string.atoi to convert a variable integer to a string?
> I have tied theese different ways...
> daverse = string.atoi(daverse)
> daverse = string.atoi(), daverse
> daverse = string.atoi("daverse")

You don't, for several reasons. :)

string.atoi() has been deprecated since release 2.0.  
Don't use it unless you're using an older version of Python.
(The replacement, as documented in the global module 
index for module "string", is the built-in int().)

The other reason you don't, is that string.atoi (and int())
converts strings which contain ASCII representations of
integers to the integer value, not the other way around.

You are probably looking for this answer, from the FAQ
(which I recommend you read thoroughly):

http://www.python.org/cgi-bin/faqw.py?query=4.45&req=search

(A last suggestion: when posting questions like this,
I recommend you type your experiments in the interactive
interpreter, and when they don't work out, cut and
paste the *entire* sequence (including the exceptions!)
into your posting.  This will make it a lot easier for
people to figure out what you really want to do, and
why what you tried didn't work.)

Cheers!
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list