#100DaysOfCode in Python Transcripts
Chapter: Days 67-69: Copy and Paste with Pyperclip
Lecture: Pyperclip Usage
Login or purchase this course to watch this video and the rest of the course contents.
0:00 Okay, this might be the quickest demonstration you're going to see in this entire course, so.
0:06 Alright, in the shell we're just going to import pyperclip. This video is just going to walk you through the pyperclip usage.
0:15 In your head just think about the whole, the way you copy and paste at the moment, so if you want to copy something
0:21 from the command line and paste it somewhere else, you're going to copy to put it on the clipboard,
0:27 and then you're going to paste it off the clipboard. Same sort of concept here, but almost reversed. So, if you want to take the user's text
0:37 that they have copied to the clipboard, you're going to paste it into your code, and then once you've manipulated it,
0:43 and you want to put it back on the clipboard, you're going to copy it out of your code. So, if we do pyperclip.paste
0:54 it's going to show you what I have on my clipboard or the last item on my clipboard, okay, which is this URL.
1:02 Now, let's say we just want to strip out the HTTPS and have just codechallenge.es there, okay. If we want to push that back to the clipboard,
1:13 we just go pyperclip.copy and then in here we put whatever we want in, okay. Now, mind you, you can make this a variable.
1:27 So, this doesn't have to be plain text. If your variable happens to contain an entire, say, book, or an entire chapter,
1:35 or an entire website worth of text, you can pop that variable in here and it'll copy it back to the clipboard.
1:44 Okay, and then just to show that that worked, let's just put pyperclip.paste back in, actually, I'm not going to copy that,
1:52 that'll override the clipboard, won't it? So, pyperclip.paste and there we have it, just the stuff that we sent back to the clipboard using copy.
2:03 Okay, one thing to then keep in mind, is that as you use this script, as you use this module pyperclip.copy and paste,
2:13 it will override what you have on your clipboard, so be careful. Just keep that in mind as you're using it, especially when you're using it in a script
2:23 that you're going to call, few times a day, you might actually end up copying over the top of something important. So, just keep that in mind.
2:32 And, now let's create some scripts.