Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##usage instructions:
- ##take the list that you want to format with multiple columns
- ##add the number of columns you want to end up with as the first line
- ##select the whole shebang and copy to the clipboard
- ##run script
- ##your clipboard now contains your list formatted as a dtext table with the desired number of columns
- ##entries go left to right then down a line
- import pyperclip as clip
- instring = clip.paste()
- inlist = instring.splitlines()
- inlist[:] = [s.strip() for s in inlist]
- cols = int(inlist[0])
- outlist = []
- outlist.append('[table] ')
- for x in range(1,cols):
- outlist.append('| ')
- outlist.append('\n')
- for x in range(1,len(inlist)):
- outlist.append(inlist[x])
- if (cols-1) == ((x-1)%cols):
- outlist.append('\n')
- else:
- outlist.append(' | ')
- if outlist[-1] == ' | ':
- outlist[-1] = '\n'
- outlist.append('[/table]')
- outstr = ''.join(outlist)
- clip.copy(outstr)
Add Comment
Please, Sign In to add comment