int <-> str asymmetric

Schüle Daniel uval at rz.uni-karlsruhe.de
Thu Mar 16 14:24:17 CET 2006


Hello

what I sometimes miss in Python is the possibility to
switch tha base of a number
for example this is how it's done in Ruby

irb(main):099:0* a = 10.to_s(2)
=> "1010"
irb(main):100:0> a.to_i(2)
=> 10
irb(main):101:0>
irb(main):102:0* a = 10.to_s(3)
=> "101"
irb(main):103:0> a.to_i(3)
=> 10

the Python int-Function behaves similar
 >>> int("1010",2)
10
 >>>

however we lack the reverse functionality
the logical

 >>> str(10,2)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: str() takes at most 1 argument (2 given)
 >>>

fails

it would not break anything if str interface would be changed
what do you think?
Is this already proposed or maybe implemented in 2.5?

Regards, Daniel




More information about the Python-list mailing list