Re: Using %x to format number to hex and number of digits

2010-11-06 Thread Steve Holden
On 11/5/2010 3:26 PM, Matty Sarro wrote: > It works, however I'm not sure if it'd be considered very "pythonic" or not. If working isn't pythonic then nothing is. > Thanks for your thoughts! There really are still some amazingly helpful people around here, I am pleased to note. regards Steve -

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Tim Chase
On 11/05/10 15:10, Grant Edwards wrote: On 2010-11-05, Tim Chase wrote: On 11/05/10 13:23, Matty Sarro wrote: I need it to output as 0x0a, and the exercise is requiring me to use %x to format the string. Any help would be appreciated. Though it feels hokey to me, using "%#04x" % 10 wor

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Grant Edwards
On 2010-11-05, Tim Chase wrote: > On 11/05/10 13:23, Matty Sarro wrote: >>> I'm currently trying to convert a digit from decimal to hex, >>> however I need the full 4 digit hex form. Python appears to >>> be shortening the form. >>> Example: >>> >>> num = 10 >>> num = "%x"%(num) >>> print(num) >>>

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Tim Chase
On 11/05/10 13:23, Matty Sarro wrote: I'm currently trying to convert a digit from decimal to hex, however I need the full 4 digit hex form. Python appears to be shortening the form. Example: num = 10 num = "%x"%(num) print(num) a num = 10 num = "%#x"%(num) print(num) 0xa I need it to ou

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Matty Sarro
I actually was able to get it working a few minutes after posting the question. My apologies for not posting a followup :) I ended up using the following format: num = 10 num = "%#0.2x"%(num) print(num) It works, however I'm not sure if it'd be considered very "pythonic" or not. Thanks for your t

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Grant Edwards
On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > I'm currently trying to convert a digit from decimal to hex, however I need > the full 4 digit hex form. Python appears to be shortening the form. > Example: > > num = 10 > num = "%x"%(num) > print(num) > >>a > > num = 10 > num = "%#x"%(num) >

Re: Using %x to format number to hex and number of digits

2010-11-05 Thread Chris Rebert
On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro wrote: > I'm currently trying to convert a digit from decimal to hex, however I need > the full 4 digit hex form. Python appears to be shortening the form. > Example: > > num = 10 > num = "%x"%(num) > print(num) > >>a > > num = 10 > num = "%#x"%(num) >

Using %x to format number to hex and number of digits

2010-11-05 Thread Matty Sarro
I'm currently trying to convert a digit from decimal to hex, however I need the full 4 digit hex form. Python appears to be shortening the form. Example: num = 10 num = "%x"%(num) print(num) >a num = 10 num = "%#x"%(num) print(num) >0xa I need it to output as 0x0a, and the exercise is requirin