Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 16th, 2006, 12:35 PM
Schüle Daniel
Guest
 
Posts: n/a
Default int <-> str asymmetric

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[color=blue][color=green][color=darkred]
>>> int("1010",2)[/color][/color][/color]
10[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]

however we lack the reverse functionality
the logical
[color=blue][color=green][color=darkred]
>>> str(10,2)[/color][/color][/color]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: str() takes at most 1 argument (2 given)[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]

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

  #2  
Old March 16th, 2006, 03:15 PM
Steven Bethard
Guest
 
Posts: n/a
Default Re: int <-> str asymmetric

Schüle Daniel wrote:[color=blue]
> however we lack the reverse functionality
> the logical
>[color=green][color=darkred]
> >>> str(10,2)[/color][/color]
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: str() takes at most 1 argument (2 given)[color=green][color=darkred]
> >>>[/color][/color]
>
> 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?[/color]

It's been proposed:

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

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

Steve
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles