mod, modulo and % under 2.4 and 2.5
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. If so, why isn't it both 2.4 and 2.5? -- http://mail.python.org/mailman/listinfo/python-list
Re: mod, modulo and % under 2.4 and 2.5
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. [st...@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 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: mod, modulo and % under 2.4 and 2.5
01-01-2010 o 02:30:20 W. eWatson wolftra...@invalid.com 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. If so, why isn't it both 2.4 and 2.5? ??? There is no builtin mod() function at all, but there are (in Py 2.4, 2.5, 2.6, 3.0 and 3.1): * builtin '%' and '%=' operators * builtin divmod() * in 'operator' module: mod() or __mod__() [the same] -- equivalents of '%' operator * in 'math' module: fmod() function Additionaly, since Py 2.5 in 'operator' module there is imod() and __imod__() [the same] -- equivalents of '%=' operator. Cheers, *j -- http://mail.python.org/mailman/listinfo/python-list
Re: mod, modulo and % under 2.4 and 2.5
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. [st...@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 So where is it? Here are the choices. import sys, os, glob import string from numpy import * from datetime import datetime, timedelta import time In the 2.4 version, I change nmnpy to Numeric -- http://mail.python.org/mailman/listinfo/python-list
Re: mod, modulo and % under 2.4 and 2.5
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. If so, why isn't it both 2.4 and 2.5? mod() not is a built-in. It is, however, in the 'operator' module, and also as __mod__() in that same module. Both are equivalent to '%'. It has been there since at least Python v2.0. As for why something might not be in an earlier version, well, that would be because it hadn't been added yet! :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: mod, modulo and % under 2.4 and 2.5
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. [st...@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'? -- http://mail.python.org/mailman/listinfo/python-list
Re: mod, modulo and % under 2.4 and 2.5
W. eWatson wolftra...@invalid.com writes: Steven D'Aprano wrote: NameError: name 'mod' is not defined So where is it? Here are the choices. import sys, os, glob import string from numpy import * If you use ‘from foo import *’ you forfeit any way of saying where a name in your code gets bound. Hence, don't do that. -- \ “Generally speaking, the errors in religion are dangerous; | `\those in philosophy only ridiculous.” —David Hume, _A Treatise | _o__) of Human Nature_, 1739 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: mod, modulo and % under 2.4 and 2.5
On Fri, 01 Jan 2010 13:48:28 +1100, Ben Finney wrote: W. eWatson wolftra...@invalid.com writes: Steven D'Aprano wrote: NameError: name 'mod' is not defined So where is it? Here are the choices. import sys, os, glob import string from numpy import * If you use ‘from foo import *’ you forfeit any way of saying where a name in your code gets bound. Not quite: from math import * sin.__module__ 'math' But this only works with functions and classes, not arbitrary objects: pi.__module__ Traceback (most recent call last): File stdin, line 1, in module AttributeError: 'float' object has no attribute '__module__' Hence, don't do that. Avoiding from module import * is generally excellent advice. There's one or two exceptions, but if you have to ask what they are, you don't need to know *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: mod, modulo and % under 2.4 and 2.5
Ben Finney wrote: W. eWatson wolftra...@invalid.com writes: Steven D'Aprano wrote: NameError: name 'mod' is not defined So where is it? Here are the choices. import sys, os, glob import string from numpy import * If you use ‘from foo import *’ you forfeit any way of saying where a name in your code gets bound. Hence, don't do that. Good idea! -- http://mail.python.org/mailman/listinfo/python-list