mod, modulo and % under 2.4 and 2.5

MRAB python at mrabarnett.plus.com
Thu Dec 31 21:24:08 EST 2009


W. eWatson wrote:
> Steven D'Aprano wrote:
>> On Thu, 31 Dec 2009 17:30:20 -0800, W. eWatson wrote:
>>
>>> About a year ago, I wrote a program that used mod() for modulo under
>>> 2.5. Apparently, % is also acceptable, but the program works quite well.
>>> I turned the program over to someone who is using 2.4, and apparently
>>> 2.4 knows nothing about mod(). Out of curiosity, what library is
>>> mod(a,b)(two args) in? It doesn't seem to be in numpy. It seems to be
>>> built-in.
>>
>> No it doesn't.
>>
>> [steve at sylar ~]$ python2.5
>> Python 2.5 (r25:51908, Nov  6 2007, 16:54:01)
>> [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> mod
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> NameError: name 'mod' is not defined
>>
>>
If you think it's built-in then you've probably imported it from a
module using the form "from some_module import *".

> So where is it? Here are the choices.
> import sys, os, glob
> import string
> from numpy import *

Aha, there you are!

> from datetime import datetime, timedelta
> import time
> 
> In the 2.4 version, I change nmnpy to Numeric

'numpy' does contain a function called 'mod'.

 >>> import numpy
 >>> numpy.mod
<ufunc 'remainder'>

Does 'Numeric'?



More information about the Python-list mailing list