/
random_gen.py
executable file
·61 lines (51 loc) · 1023 Bytes
/
random_gen.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import random
import os
import time
#generate once
#name = ""
#li = []
#while name != "00":
# name = raw_input("Items: ")
# if name == "00":
# pass
# else:
# li.append(name)
#li = ['Gitonga','Mandela','Kevin','Kimani','Cetric','Robert']
#def gen():
# random.shuffle(li)
# for i in li:
# print i
#gen()
#randomise from a file
def gen():
try:
import docx
except:
print "Please type the command 'pip install docx' to continue"
file_name = raw_input("Enter the file name to randomise words from: ")
if file_name.endswith("docx"):
acc = open(file_name,"r")
file_obj = acc.xreadlines()
open_docx = docx.opendocx(file_obj)
data = docx.getdocumenttext(open_docx)
random.shuffle(data)
for i in data:
if i == "\n":
pass
else:
print i
time.sleep(0.5)
else:
acc = open(file_name,"r")
li = acc.readlines()
acc.close()
random.shuffle(li)
for i in li:
if i == "\n":
pass
else:
print i
time.sleep(0.5)
gen()
#path = os.getcwd()
#file_in = path + file_name