string.py

Moshe Zadka moshez at math.huji.ac.il
Fri Feb 18 11:42:41 EST 2000


On Fri, 18 Feb 2000, Gerrit Holl wrote:

> > Python 1.5.2+ (#276, Feb  1 2000, 15:08:05)  [GCC 2.8.1] on sunos5
> > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> > >>> int('123', 8)
> > 83
> 
> Cool. Will there also be something the other way?
> I can convert int 83 to an octal or hexadecimal string,
> but I want to convert it to a string with an arbitrary radix,
> for example, 2, to see what it is in binary. Of course,
> I could code it myself, but a better half[1] would be a
> Good Thing(tm).

I think Gerrit is on to something. How about....(drum roll)...int methods?

I mean, we've broken the barrier with string methods, so there's no 
reason not to allow:

>>> a = 5.radix(2)
>>> print `a`
"101"
>>>

I see there might be parser problems, but maybe (5).radix? Python seems
willing to check for it:

>>> a = (5).radix(2)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AttributeError: 'int' object has no attribute 'radix'

totally-out-of-my-head-ly y'rs, Z.
--
Moshe Zadka <mzadka at geocities.com>. 
INTERNET: Learn what you know.
Share what you don't.





More information about the Python-list mailing list