Reading in strings -> numbers ??

emile at fenx.com emile at fenx.com
Fri Apr 28 20:30:27 EDT 2000


If you're trying to put the info on disk to read it
in again later, look at eval(repr()), eg:

>>> a,b,c = eval(repr((1.2, -3.5, 10)))
>>> a,b,c
(1.2, -3.5, 10)
>>> 

Emile van Sebille

Louis M. Pecora <pecora at anvil.nrl.navy.mil> wrote in message
news:<280420001700308281%pecora at anvil.nrl.navy.mil>...
> Is there a Python "read-partner" for the write(string) function, e.g., 
> 
> fileobject.write(" %e %e %d" % (1.2, -3.5, 10))  
> 
> in the sense that the C functions fprintf and fscanf are partners.
> 
> I've looked in 4 different Python books and in the pdf references, but
> I see nothing in read or readlines or strings that seems to make for an
> easy conversion from a string to a list or tuple of objects (numbers). 
> In other words, I want the opposite of the write above so I can read
> those numbers back into my Python code.  
> 
> Thanks for any help.
> -- 
> http://www.python.org/mailman/listinfo/python-list
>




More information about the Python-list mailing list