How to convert a number to binary?

Steve Holden steve at holdenweb.com
Fri May 18 16:34:33 EDT 2007


Lyosha wrote:
> On May 17, 11:10 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
> 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(15, 2)
>>
>> Carrying a whole lot of one-liners around in your head is a waste of
>> neurons. Neurons are far more valuable than disk space, screen lines,
>> or CPU cycles.
> 
> While I agree with this general statement, I think remembering a
> particular one-liner to convert a number to a binary is more valuable
> to my brain than remembering where I placed the module that contains
> this function.
> 
> I needed the one-liner not to save disk space or screen lines.  It's
> to save time, should I need to convert to binary when doing silly
> little experiments.  I would spend more time getting the module
> wherever it is I stored it (and rewriting it if it got lost).
> 
> It's fun, too.
> 
Id use the "silly little module" even for experiments. Most Python 
programmers keep a directory full of such "stock" modules.

regards
  Steve




More information about the Python-list mailing list