How to convert a number to binary?

2007-05-17 Thread Lyosha
Converting binary to base 10 is easy: >>> int('', 2) 255 Converting base 10 number to hex or octal is easy: >>> oct(100) '0144' >>> hex(100) '0x64' Is there an *easy* way to convert a number to binary? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to convert a number to binary?

2007-05-17 Thread Lyosha
On May 17, 4:40 pm, Michael Bentley <[EMAIL PROTECTED]> wrote: > On May 17, 2007, at 6:33 PM, Lyosha wrote: > > > Converting binary to base 10 is easy: > >>>> int('', 2) > > 255 > > > Converting base 10 number to hex or octal is

Re: How to convert a number to binary?

2007-05-18 Thread Lyosha
On May 17, 11:04 pm, Stargaming <[EMAIL PROTECTED]> wrote: [...] > >>>Is there an *easy* way to convert a number to binary? [...] > > Wrote this a few moons ago:: > >dec2bin = lambda x: (dec2bin(x/2) + str(x%2)) if x else '' This is awesome. Exactly what I was looking for. Works for other ba

Re: How to convert a number to binary?

2007-05-18 Thread Lyosha
On May 17, 11:10 pm, Ben Finney <[EMAIL PROTECTED]> wrote: [...] > > That's way too complicated... Is there any way to convert it to a > > one- liner so that I can remember it? > > You put in a module so you don't *have* to remember it. > > Then, you use it in this one-liner: > > foo = to_base

Re: Inheriting from Python list object(type?)

2007-05-23 Thread Lyosha
On May 23, 12:07 pm, Mangabasi <[EMAIL PROTECTED]> wrote: > On May 23, 1:43 pm, "Jerry Hill" <[EMAIL PROTECTED]> wrote: > > > > > On 23 May 2007 11:31:56 -0700, Mangabasi <[EMAIL PROTECTED]> wrote: > > > > When I modified this to: > > > > class Point(list): > > > def __init__(self,x,y): > > >

Re: Inheriting from Python list object(type?)

2007-05-23 Thread Lyosha
On May 23, 12:07 pm, Mangabasi <[EMAIL PROTECTED]> wrote: > On May 23, 1:43 pm, "Jerry Hill" <[EMAIL PROTECTED]> wrote: > > > > > On 23 May 2007 11:31:56 -0700, Mangabasi <[EMAIL PROTECTED]> wrote: > > > > When I modified this to: > > > > class Point(list): > > > def __init__(self,x,y): > > >

Re: Inheriting from Python list object(type?)

2007-05-23 Thread Lyosha
On May 23, 12:07 pm, Mangabasi <[EMAIL PROTECTED]> wrote: > On May 23, 1:43 pm, "Jerry Hill" <[EMAIL PROTECTED]> wrote: > > > > > On 23 May 2007 11:31:56 -0700, Mangabasi <[EMAIL PROTECTED]> wrote: > > > > When I modified this to: > > > > class Point(list): > > > def __init__(self,x,y): > > >

Re: Inheriting from Python list object(type?)

2007-05-23 Thread Lyosha
On May 23, 12:19 pm, Lyosha <[EMAIL PROTECTED]> wrote: > On May 23, 12:07 pm, Mangabasi <[EMAIL PROTECTED]> wrote: > > > On May 23, 1:43 pm, "Jerry Hill" <[EMAIL PROTECTED]> wrote: > > > > On 23 May 2007 11:31:56 -0700, Mangabasi <[EMA