Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > int <-> str asymmetric

Reply
Thread Tools

int <-> str asymmetric

 
 
=?ISO-8859-1?Q?Sch=FCle_Daniel?=
Guest
Posts: n/a
 
      03-16-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

 
Reply With Quote
 
 
 
 
Steven Bethard
Guest
Posts: n/a
 
      03-16-2006
Schüle Daniel wrote:
> 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?


It's been proposed:

http://mail.python.org/pipermail/pyt...ry/059789.html

But it didn't look like there was a resolution.

Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
It is fun.the result of str.lower(str()) Sullivan WxPyQtKinter Python 5 03-09-2006 08:09 AM
sizeof(str) or sizeof(str) - 1 ? Trevor C Programming 9 04-10-2004 05:07 PM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
what's the deference between str=null and str=" " ???????? David Java 2 08-03-2003 04:10 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57