-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_processing.py
More file actions
55 lines (45 loc) · 1.45 KB
/
image_processing.py
File metadata and controls
55 lines (45 loc) · 1.45 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
import sys, os
def to_clean_list(file):
as_list = []
for line in file:
as_list.append(line)
clean_list = [q.replace('\n', ' ') for q in as_list]
return clean_list
def longest_line(cln_lst):
longest = max(len(long) for long in cln_lst)
return longest
def add_spaces(clean_list, longest):
equal_list = []
for c,x in enumerate(clean_list):
while len(x) < longest:
x += " "
equal_list.append(x)
return equal_list
def horizontal_to_vertical(longest, equal_length):
result = []
for x in range(longest):
for y, z in enumerate(equal_length):
result.append(z[x])
if not y % longest:
if not x and not y:
continue
else:
result.append('\n')
return result
def rotate(file):
clean_list = to_clean_list(file.readlines())
longest = longest_line(clean_list)
equal_length = add_spaces(clean_list,longest)
result = horizontal_to_vertical(longest, equal_length)
return result
if __name__=='__main__':
try:
file_name=sys.argv[1]
except:
print(f'Error: file not specified\nUsage: python {os.path.basename(__file__)} file.txt')
exit()
with open("output.txt", "w") as output:
with open(sys.argv[1]) as file:
result = rotate(file)
output.writelines(result)
print('Done, Check output.txt')