[PYTHON DB-SIG] Converting strings to numbers

Hal J Schechner hal-j@alpha.netusa.net
Wed, 23 Oct 1996 09:13:08 -0400 (EDT)


On Wed, 23 Oct 1996, Fredrik Lundh wrote:

> 
> > This can not only be done from string reps of a number to a numeric
> > type, but also from string reps of anything (lists, tuples, dicts
> > etc..) to thier actual type. ( nice for reading plaintext datafiles
> > ).
> 
> Note that eval is compact but dangerous; consider the following (on a
> Unix box):
> 
> 	eval('os.remove("rm -rf ~/*")')
> 
> Use string.atoi() and string.atof() when you need to be on the safe
> side.
> 

This is fine when working with floats or integers, but like I stated, there
are times (like when trying to restore tuples, lists etc..) when you cant
use one of the lib functions.  Of course, you would want to make sure you
are safe when you do it, and making a wrapper would be the 'right' way of
doing it.  I was only pointing out that it *is* possible to do it ;)

-Hal Schechner
-=[Hal Schechner]-=-=-=-=System Administration=-=-=-=-=(hal-j@NetUSA.Net)=-
       Are you SURE no one changed ANYTHING in your configuration?!?!       
-=[Finger for public key]-=-=-=-=-=-=-=-=-=[http://www.NetUSA.Net/~hal-j]=-


=================
DB-SIG  - SIG on Tabular Databases in Python

send messages to: db-sig@python.org
administrivia to: db-sig-request@python.org
=================