-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrorschach.py
More file actions
59 lines (47 loc) · 1.58 KB
/
rorschach.py
File metadata and controls
59 lines (47 loc) · 1.58 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
import argparse
import os
import os.path
import random
class Rorschach:
cols = 0
rows = 0
str_rep = ""
def __init__(self, cols, rows, items):
self.cols = cols
self.rows = rows
shuffled = random.sample(items, len(items))
matrix = self._create_matrix(shuffled)
self._set_str_representation(matrix)
def __str__(self):
return self.str_rep
def _create_matrix(self, items):
return list(zip(*[iter(items)]*self.cols))[0:self.rows]
def _set_str_representation(self, matrix):
for arr in matrix:
self.str_rep += ", ".join(arr) + "\n"
cols = 3
rows = 1
file_name = 'items.txt'
parser = argparse.ArgumentParser(description='Given a list of words, it creates a table from it.')
parser.add_argument('columns', type=int, nargs='?',
help='number of columns', default=cols)
parser.add_argument('rows', type=int, nargs='?',
help='number of rows', default=rows)
parser.add_argument('filename', nargs='?',
help='filename of word list', default=file_name)
args = parser.parse_args()
cols = args.columns
rows = args.rows
file_name = args.filename
path = os.path.join(os.getcwd(), file_name)
if not os.path.isfile(path):
file = open(path, "w+")
file.write("write list of expressions here\nseparate them by line breaks\nall is well")
file.close()
else:
file = open(path, "r")
items = file.read().split('\n')
file.close()
print 'Using {0} as word list.\n'.format(path)
print(Rorschach(cols, rows, items))