-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprinter.py
49 lines (36 loc) · 1.22 KB
/
printer.py
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
45
46
import os.path
'''
printer function that prints saddles to a file
@param filename - string
@param saddles - list(list(int))
'''
def printSaddlesToFile(filename, saddles):
saddle_string = ""
for i in saddles:
saddle_string = saddle_string + "SS: "
index_string = ""
for indices in i.indices:
index_string = index_string + "["
for j in range(len(indices)):
if j == len(indices)-1:
index_string = index_string + str(indices[j]) + "] "
else:
index_string = index_string + str(indices[j]) + ","
saddle_string = saddle_string + index_string + "\n"
with open(filename, 'w') as out_file:
out_file.write(saddle_string)
#print "Writing\n" + saddle_string + "to file \'" + filename + "\'"
print saddle_string
'''
printer function that prints the saddle size to a file (if the file exists the size gets appended)
@param filename - string
@param saddlesite - int
!!! only works if the file already exists !!!
'''
def printSaddleSizeToFile(filename, saddlesize):
#if not os.path.isfile(filename):
# print str(filename) + " does not exist, please create it before running the script!"
#else:
with open(filename, 'a') as out_file:
size_string = str(saddlesize) + " "
out_file.write(size_string)