#100DaysOfCode in Python Transcripts
Chapter: Days 67-69: Copy and Paste with Pyperclip
Lecture: Pyperclip Usage
0:00 Okay, this might be the quickest demonstration
0:02 you're going to see in this entire course, so.
0:05 Alright, in the shell we're just going to import pyperclip.
0:09 This video is just going to walk you
0:10 through the pyperclip usage.
0:14 In your head just think about the whole,
0:15 the way you copy and paste at the moment,
0:18 so if you want to copy something
0:20 from the command line and paste it somewhere else,
0:23 you're going to copy to put it on the clipboard,
0:26 and then you're going to paste it off the clipboard.
0:29 Same sort of concept here, but almost reversed.
0:33 So, if you want to take the user's text
0:36 that they have copied to the clipboard,
0:38 you're going to paste it into your code,
0:41 and then once you've manipulated it,
0:42 and you want to put it back on the clipboard,
0:45 you're going to copy it out of your code.
0:47 So, if we do pyperclip.paste
0:53 it's going to show you what I have on my clipboard
0:55 or the last item on my clipboard, okay, which is this URL.
1:01 Now, let's say we just want to strip out the HTTPS
1:04 and have just codechallenge.es there, okay.
1:09 If we want to push that back to the clipboard,
1:12 we just go pyperclip.copy
1:18 and then in here we put whatever we want in, okay.
1:23 Now, mind you, you can make this a variable.
1:26 So, this doesn't have to be plain text.
1:28 If your variable happens to contain an entire, say,
1:33 book, or an entire chapter,
1:34 or an entire website worth of text,
1:39 you can pop that variable in here
1:41 and it'll copy it back to the clipboard.
1:43 Okay, and then just to show that that worked,
1:46 let's just put pyperclip.paste back in,
1:50 actually, I'm not going to copy that,
1:51 that'll override the clipboard, won't it?
1:53 So, pyperclip.paste and there we have it,
1:58 just the stuff that we sent back
2:00 to the clipboard using copy.
2:02 Okay, one thing to then keep in mind,
2:06 is that as you use this script,
2:08 as you use this module pyperclip.copy and paste,
2:12 it will override what you have on your clipboard,
2:15 so be careful.
2:17 Just keep that in mind as you're using it,
2:19 especially when you're using it in a script
2:22 that you're going to call, few times a day,
2:26 you might actually end up copying
2:28 over the top of something important.
2:29 So, just keep that in mind.
2:31 And, now let's create some scripts.