Showing posts with label pyperclip.paste(). Show all posts
Showing posts with label pyperclip.paste(). Show all posts

Wednesday, July 5, 2017

Copying with Pyperclip


Pyperclip is a python module for copying and pasting clipboard content. pyperclip.copy() and pyperclip.paste() functions are the main functions of the modules and works in the same manner as the name implied. Peruse the below code and try to grasp what the code will do -

import pyperclip

while True:
    fh=open('allcopies1.txt','a+')    
    text=str(pyperclip.paste())
    if text not in str(fh.read()):
        fh.write(text)
        fh.write("\n\r\n")
    else:
        print "Already Copied"
        fh.close()
        break
fh=open('allcopies1.txt','r')
for word in fh:
    print word
       

This program is useful when you need to have a file for storing all the copied content. Make sure the file has a 777 permission. After opening the file we check if the content of the clipboard copied previously? If not then it adds the clipboard content to the file.
A small but useful tool for big future programs. Can you name me instances when it can be used.

ref: Automate boring stuff by python.

Feautured Post

Python Trivia Post: enumerate()

Python has a very useful inbuilt function, which is called enumerate(). This is needed whenever you need the numbering of a certain element...