jgtrosh

boxesminus.py

Aug 5th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import os
  2. class box:
  3.     def __init__(self, text):
  4.         t = []
  5.         maxlen = []
  6.         text = text.split("[p]")
  7.         for i, p in enumerate(text):
  8.             p = p.split('[l]')
  9.             maxlen.append(max(len(line) for line in p))
  10.             t.append('')
  11.             for line in p:
  12.                 t.append(' \033[47;30m'+line+' '*(maxlen[i]-len(line))+'\033[0m')
  13.         t.append('')
  14.         self.t = t
  15.         del t, maxlen, i
  16.     def output(self):
  17.         print('\n'.join(self.t))
  18.  
  19. if __name__ == '__main__':
  20.     a = box('this is the first box\
  21. [l]as you can see\
  22. [p]now you\'re reading the content from the second box\
  23. [p]we just switched to the third box\
  24. [l]not as large a box\
  25. [l]though slightly higher\
  26. [l]you can see that even though\
  27. [l]it goes on and on\
  28. [l]nothing broke yet\
  29. [l](well i hope so at least)\
  30. [p]anyway we reached the last box\
  31. [l]so it\'s time for good byes')
  32.     a.output()
  33.     if 'win' in os.sys.platform:
  34.         os.system('PAUSE')
Advertisement
Add Comment
Please, Sign In to add comment