More random python observations from a perl programmer
Magnus L. Hetland
mlh at idt.ntnu.no
Sat Aug 21 10:00:38 EDT 1999
Lars Damerow <lars at pixar.com> writes:
> On 19 Aug 1999, Tom Christiansen wrote:
>
> > No, that's not it. Perl's hex takes a hex number and returns
> > a decimal one; same with oct. Python's is the reverse. Very weird.
> >
> > echo 'print oct(12)' | python
> > 14
> >
> > echo 'print oct(12)' | perl -l
> > 10
> >
> > See what I mean?
>
> I don't consider that weird at all. Take casting, for example, in any number
> of languages. If, in C++, I say int(var), that takes var and casts it to be an
> integer. I might say long(num) in Python, which says "Turn num into a long."
>
> In that case, doesn't it make sense that hex(12) would take the decimal number
> 12 and return '0xc'? That oct(153) returns '0231'? Functions and methods are
> typically named for the action they perform, not the data they're accepting.
Indeed... I would be very distressed if sin(0.9) returned 2... Or
sqrt(2) returned 4... Or, indeed if oct(12) returned 14. Very
disturbing.
>
> -lars
--
Magnus Making no sound / Yet smouldering with passion
Lie The firefly is still sadder / Than the moaning insect
Hetland : Minamoto Shigeyuki
More information about the Python-list
mailing list