String to int newbie question

OKB (not okblacke) BrenBarn at aol.com
Sun Mar 23 03:14:46 CET 2003


Luka Milkovic wrote:

> The things I need to do is to change the strings inside
> the list to integers and then write the list to a file ( I know how
> to do the latter:). The problem is, if I change it with
> int(my_string_inside_the_list) I won't get the same numbers, and I
> need to have the content of the string and integer the same. So,
> after the conversion of that list, what I want to have is: [4312,
> 7599, 0724, 0003] and NOT [4312, 7599, 724, 3].
> Can you solve my problem?
> Your help will be appreciated.

    	What you seem not to understand is that where integers are 
concerned all that matters is the VALUE.  The representation in decimal 
digits is just a matter of convention.  It's the same as if I were to 
verbally say to you "three" and ask you to write it down.  You could 
write that as "3", or "0003", or "3.000000", and all would be correct -- 
the value is still this many: * * *.  Things like leading zeros are 
purely a matter of the display.

    	If you need to store the leading zeros, you need to output strings 
with leading zeros.

-- 
--OKB (not okblacke)
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
	--author unknown




More information about the Python-list mailing list