1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Special module for checking types."""
24
25
26 io_module = True
27 try:
28 from io import IOBase
29 file = None
30 except ImportError:
31 io_module = False
32 from numpy import float32, float64, ndarray
33 try:
34 from numpy import float16
35 except ImportError:
36 float16 = float32
37 try:
38 from numpy import float128
39 except ImportError:
40 float128 = float64
41
42
44 """Check if the given Python object is a file.
45
46 @param obj: The Python object.
47 @type obj: anything
48 @return: True if the object is a file, False otherwise.
49 @rtype: bool
50 """
51
52
53 if io_module:
54 return isinstance(obj, IOBase)
55
56
57 else:
58 return isinstance(obj, file)
59
60
62 """Check if the given number is a Python or numpy float.
63
64 @param num: The number to check.
65 @type num: anything.
66 @return: True if the number is a float, False otherwise.
67 @rtype: bool
68 """
69
70
71 if isinstance(num, float):
72 return True
73
74
75 if isinstance(num, float16):
76 return True
77 if isinstance(num, float32):
78 return True
79 if isinstance(num, float64):
80 return True
81 if isinstance(num, float128):
82 return True
83
84
85 return False
86
87
89 """Check if the given Python object is a unicode string.
90
91 @param obj: The Python object.
92 @type obj: anything
93 @return: True if the object is a unicode string, False otherwise.
94 @rtype: bool
95 """
96
97
98 return isinstance(obj, unicode)
99