Guest User

Untitled

a guest
Jan 12th, 2017
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. ##usage instructions:
  2. ##take the list that you want to format with multiple columns
  3. ##add the number of columns you want to end up with as the first line
  4. ##select the whole shebang and copy to the clipboard
  5. ##run script
  6. ##your clipboard now contains your list formatted as a dtext table with the desired number of columns
  7. ##entries go left to right then down a line
  8.  
  9. import pyperclip as clip
  10. instring = clip.paste()
  11. inlist = instring.splitlines()
  12. inlist[:] = [s.strip() for s in inlist]
  13. cols = int(inlist[0])
  14. outlist = []
  15. outlist.append('[table] ')
  16. for x in range(1,cols):
  17.     outlist.append('| ')
  18. outlist.append('\n')
  19. for x in range(1,len(inlist)):
  20.     outlist.append(inlist[x])
  21.     if (cols-1) == ((x-1)%cols):
  22.         outlist.append('\n')
  23.     else:
  24.         outlist.append(' | ')
  25. if outlist[-1] == ' | ':
  26.     outlist[-1] = '\n'
  27. outlist.append('[/table]')
  28. outstr = ''.join(outlist)
  29. clip.copy(outstr)
Add Comment
Please, Sign In to add comment