Is this a good idea or a waste of time?
Jonathan Gardner
jgardner at jonathangardner.net
Tue Aug 29 03:13:18 EDT 2006
Simon Forman wrote:
>
> If you have a reason to restrict your code to using only ints (perhaps
> you're packing them into an array of some sort, or passing them to a C
> extension module) then yes, of course it's appropriate.
I politely disagree. Rather than an interface that demands an actual
int, demand something that can be typecast as an int.
For instance:
def needsInt(i):
i = int(i)
... pass i to an internal c function that requires an int ...
# Or better yet, write your internal c function to take any Python
object and cast it into an int.
If you absolutely need a particular type of thing, then cast it into
that thing.
More information about the Python-list
mailing list