Created
January 29, 2024 14:08
-
-
Save knu2xs/b8fdcc130e8fbf88bad127243f39be58 to your computer and use it in GitHub Desktop.
Copy to Clipboard Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def copy_to_clipboard(string: str) -> None: | |
""" | |
Copy a string to the system clipboard. | |
.. note:: | |
This leans on Pandas, so it will not work unless Pandas is installed. | |
""" | |
# ensure Pandas is installed and available | |
if not importlib.util.find_spec('pandas'): | |
raise EnvironmentError('copy_to_clipboard requires Pandas. Please ensure Pandas is installed in the environment to use.') | |
# late import after checking for Pandas | |
from pandas.io.clipboard import clipboard_set | |
# use clipboard_set to push to clipboard | |
clipboard_set(string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment