Skip to content

Instantly share code, notes, and snippets.

@coreyhermanson
Created June 30, 2016 16:52
Show Gist options
  • Save coreyhermanson/99c397e280441613626a5a1578d691e4 to your computer and use it in GitHub Desktop.
Save coreyhermanson/99c397e280441613626a5a1578d691e4 to your computer and use it in GitHub Desktop.
Takes a list of strings and copies them to the Clipboard, ready to paste. Useful function if you need to copy a list of results into Excel or Notepad++. Uses Python and pyperclip module.
#!/usr/bin/env python
import pyperclip
example_list = ["Line 1", "Line 2", "Line 3", "forever and ever"]
def list_to_clipboard(output_list):
""" Check if len(list) > 0, then copy to clipboard """
if len(output_list) > 0:
pyperclip.copy('\n'.join(output_list))
print('Copied to clipboard: ')
else:
print("There was nothing on the clipboard")
print(example_list)
list_to_clipboard(example_list)
@clarkelsimon
Copy link

This command doesn't work for a python virtual machine symced with Android system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment