Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- class box:
- def __init__(self, text):
- t = []
- maxlen = []
- text = text.split("[p]")
- for i in range(len(text)):
- text[i] = text[i].split('[l]')
- maxlen.append(max(len(line) for line in text[i]))
- if i == 0:
- t.append(' '+'_'*(maxlen[i]+2))
- elif maxlen[i-1] < maxlen[i]:
- t.append('|'+'_'*(maxlen[i-1]+2)+'|'+'_'*(maxlen[i]-maxlen[i-1]-1))
- else:
- t.append('|'+'_'*(maxlen[i-1]+2)+'|')
- t.append('|'+' '*(maxlen[i]+2)+'|')
- for line in text[i]:
- t.append('| '+line+' '*(maxlen[i]+1-len(line))+'|')
- t.append('|'+'_'*(maxlen[len(text)-1]+2)+'|')
- self.t = t
- del t, maxlen, i
- def output(self):
- for line in self.t:
- print(line)
- if __name__ == '__main__':
- a = box('this is the first box\
- [l]as you can see\
- [p]now you\'re reading the content from the second box\
- [p]we just switched to the third box\
- [l]not as large a box\
- [l]though slightly higher\
- [l]you can see that even though\
- [l]it goes on and on\
- [l]nothing broke yet\
- [l](well i hope so at least)\
- [p]anyway we reached the last box\
- [l]so it\'s time for good byes')
- a.output()
- if 'win' in os.sys.platform:
- os.system('PAUSE')
- ===========================================================
- $ python boxes.py
- _______________________
- | |
- | this is the first box |
- | as you can see |
- |_______________________|____________________________
- | |
- | now you're reading the content from the second box |
- |____________________________________________________|
- | |
- | we just switched to the third box |
- | not as large a box |
- | though slightly higher |
- | you can see that even though |
- | it goes on and on |
- | nothing broke yet |
- | (well i hope so at least) |
- |___________________________________|
- | |
- | anyway we reached the last box |
- | so it's time for good byes |
- |________________________________|
Advertisement
Add Comment
Please, Sign In to add comment