No it doesn't.
[steve@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
???
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
In the 2.4 version, I change nmnpy to Numeric
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! :-)
> 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'?
> 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
> "W. eWatson" <wolft...@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