forked from sdas1/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
44 lines (29 loc) · 1.13 KB
/
helpers.py
File metadata and controls
44 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import numpy as np
import types
def is_prime(n):
"""simple function to check if a given integer is prime"""
# no change necessary here
if n <= 1:
return False
if n > 2 and n % 2 == 0:
return False
for i in range(3, int(np.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True
def pretty_print_bool_array(array):
"""this function will print a boolean array such that True values are 'x'
and False values are '.'"""
with np.printoptions(formatter={"bool": lambda b: "x" if b else "."}):
print(array)
def imports_of_your_file(filename, testfile):
""" Yields all imports in the testfile. """
for name, val in vars(testfile).items():
if isinstance(val, types.ModuleType):
# get direct imports
yield val.__name__
else:
# get from x import y imports
imprt = getattr(testfile, name)
if hasattr(imprt, "__module__") and not str(imprt.__module__).startswith("_") and not str(imprt.__module__) == filename:
yield imprt.__module__