NZMATH
1.2.0
About:
NZMATH
is a Python based number theory oriented calculation system.
Fossies
Dox
:
NZMATH-1.2.0.tar.gz
("inofficial" and yet experimental doxygen-generated source code documentation)
compatibility.py
Go to the documentation of this file.
1
"""
2
compatibility between Python version
3
"""
4
5
# __builtins__.set is in >=2.4, sets.Set is in >=2.3.
6
# Be careful that the compatibility is not perfect.
7
try
:
8
set, frozenset
9
except
NameError:
10
import
sets
11
__builtins__[
"set"
] = sets.Set
12
__builtins__[
"frozenset"
] = sets.ImmutableSet
13
del sets
14
15
# __builtins__.cmp is only in <3.0.
16
# Be careful that the compatibility is not perfect.
17
try
:
18
cmp
19
except
NameError:
20
cmp =
lambda
x,y: (x>y) - (x<y)
21
__builtins__[
"cmp"
] = cmp
22
del cmp
23
24
# builtin len() raises OverflowError when the result > sys.maxint.
25
# I'm not sure this restriction will go away in the future.
26
# The following function card() ought to be used instead of len()
27
# for obtaining cardinality of sets or set-like objects.
28
def
card
(virtualset):
29
"""
30
Return cardinality of the virtualset.
31
"""
32
if
hasattr(virtualset,
"card"
):
33
return
virtualset.card()
34
return
len(virtualset)
35
36
__builtins__[
"card"
] = card
nzmath.compatibility.card
def card(virtualset)
Definition:
compatibility.py:28
nzmath
compatibility.py
Generated by
1.8.16