Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy content inside of a txt file to clipboard? [duplicate]

I have a txt file on my Desktop: test.txt. I want to open that txt file and copy everything to the clipboard.

How do I do it?

I figured how to open file and read lines:

path = 'C:\Users\Username\Desktop\test.txt'

fo = open(path, 'r').readlines()

But I can't figure out how to get that data into the clipboard.

like image 767
Towelie Avatar asked Nov 18 '25 11:11

Towelie


1 Answers

You can try using Pyperclip

import pyperclip
fo = open(path, 'r').read()
pyperclip.copy(fo)

If you're on OS X, you can also try this code:

import os 
data = "hello world"
os.system("echo '%s' | pbcopy" % data)
like image 190
Philip I Avatar answered Nov 20 '25 03:11

Philip I



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!