Re: [Tutor] Convert string to long

2011-02-24 Thread Joel Goldstick
On Thu, Feb 24, 2011 at 9:03 AM, tee chwee liong wrote: > >>> '0x' + hex(543)[2:].zfill(5) > '0x0021f' > > this is a good way but it's still in string format. but if i convert it to > long, then the leading 0s will be truncated. i guess can't have it both way. > > > > > > > > > > ___

Re: [Tutor] Convert string to long

2011-02-24 Thread Andre Engels
On Thu, Feb 24, 2011 at 3:03 PM, tee chwee liong wrote: '0x' + hex(543)[2:].zfill(5) > '0x0021f' > > this is a good way but it's still in string format. but if i convert it to > long, then the leading 0s will be truncated. i guess can't have it both way. A long is just a number. You cannot s

Re: [Tutor] Convert string to long

2011-02-24 Thread tee chwee liong
>>> '0x' + hex(543)[2:].zfill(5) '0x0021f' this is a good way but it's still in string format. but if i convert it to long, then the leading 0s will be truncated. i guess can't have it both way. ___ Tutor maillist - Tutor@python.org To un

Re: [Tutor] Convert string to long

2011-02-24 Thread Joel Goldstick
On Thu, Feb 24, 2011 at 8:08 AM, Walter Prins wrote: > > > On 24 February 2011 11:50, tee chwee liong wrote: > >> > int(s,16) for a hex string >> > >> >> great but the leading zeroes are being truncated. >> > > You need to seperate the concept of display/formatting of some thing from > the actu

Re: [Tutor] Convert string to long

2011-02-24 Thread Walter Prins
On 24 February 2011 11:50, tee chwee liong wrote: > > int(s,16) for a hex string > > > > great but the leading zeroes are being truncated. > You need to seperate the concept of display/formatting of some thing from the actual thing/value being displayed. Normally when we humans communicate num

Re: [Tutor] Convert string to long

2011-02-24 Thread tee chwee liong
> int(s,16) for a hex string > great but the leading zeroes are being truncated. i want it to be: 0x00180400L >>> array0='00180400' >>> array1='' >>> array=array0+array1 >>> a=int(a

Re: [Tutor] Convert string to long

2011-02-24 Thread Steven D'Aprano
tee chwee liong wrote: hi, is there a way to convert from string to long? my_string = "1234" my_long = long(my_string) We're happy to help you, but you should make some effort to help yourself. Have you worked through the Python tutorial? Don't just *read* it, actually follow the instruct

Re: [Tutor] Convert string to long

2011-02-24 Thread Alan Gauld
"tee chwee liong" wrote is there a way to convert from string to long? for eg: i want to concatenate all the arrays into data and make it same type (long) as data1. int() should work ok. Just remember to supply the base: eg. int(s,16) for a hex string HTH, Alan G. __