More random python observations from a perl programmer

Lars Damerow lars at pixar.com
Fri Aug 20 19:22:18 EDT 1999


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.

-lars

___________________________________________________________
lars damerow
technomonkey
pixar animation studios
lars at pixar.com

"Okay, there's the house.  I'm not stopping the car, so you'll have to
jump out."






More information about the Python-list mailing list