forked from kholidfu/githon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline_splitter.py
More file actions
39 lines (30 loc) · 1.09 KB
/
line_splitter.py
File metadata and controls
39 lines (30 loc) · 1.09 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
#!/usr/bin/python
# Kholid Fuadi
# @sopier
# Tue Aug 7 00:15:29 WIT 2012
"""Simple module to cut long line ( >n characters)
Note: You can do this using textwrap library too
"""
def line_cutter(line, num):
n = len(line) / num
newline = []
breaker_lama = 0
for i in range(1, n+1):
breaker = line[:num*i].rfind(' ')
newline.append(line[breaker_lama:breaker] + '\n')
breaker_lama = breaker + 1
newline.append(line[breaker_lama:] + '\n')
newline = ''.join(newline)
return newline
if __name__ == '__main__':
# open new file
# newfile = open('/tmp/dummy.txt', 'w')
# save it to newfile
#with open('/home/banthink/Dropbox/kuliah/latex_lat/tesis-latex/tesis_latex.tex') as f:
# for line in f:
# if len(line) > 79:
# newfile.write(line_cutter(line, 70))
# else:
# newfile.write(line)
longline = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,"
print line_cutter(longline, 50)