-
Notifications
You must be signed in to change notification settings - Fork 0
/
writetofillet.py
40 lines (28 loc) · 988 Bytes
/
writetofillet.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
import sys
arguments = sys.argv[1:]
argumentLength = len(arguments)
messageErrorArgs = "ERROR: Wrong number of arguments"
messageUsage = "Usage: writetofillet word timestorepeat filename"
print(messageUsage)
if argumentLength != 3:
sys.exit(messageErrorArgs)
word = arguments[0]
times = int(arguments[1])
filename = arguments[2]
hasNewLine = "\\n" in word
if hasNewLine:
word = word.replace("\\n", "")
print(hasNewLine)
messagePlay = "Writetofillet, writing {word} {times} time(s) at {filename}".format(word=word, times=times, filename=filename)
print(messagePlay)
textFile = open(filename, "w")
print("Successfully opened file, {filename}".format(filename=filename))
for x in range(0, 5):
print("{percent}% completed".format(percent=x*20))
for y in range(0*x, times//5*(x+1)):
f = textFile.write(word)
if hasNewLine:
textFile.write("\n")
print("100% completed")
textFile.close()
print("Closed file successfully, finished writing")