Latest / Talk Python To Me / #19: Automate the Boring Stuff with Python
Transcript
- 0:00You know, some of the things we do in life are tedious and boring.
- 0:03They're the kind of things that machines or maybe robots could do.
- 0:07So let's build those machines.
- 0:09This is Talk Python, and we'll be automating the boring stuff with Al Swigert.
- 0:13It's show number 19, recorded Thursday, July 2nd, 2015.
- 0:18Hello, and welcome to Talk Python To Me, a weekly podcast on Python.
- 0:48The language, the libraries, the ecosystem, and the personalities.
- 0:51This is your host, Michael Kennedy.
- 0:53Follow me on Twitter, where I'm @mkennedy,
- 0:56and keep up with the show and listen to past episodes at talkpythontimmy.com.
- 1:00Also, follow the show on Twitter, where it's at Talk Python.
- 1:04This episode, we'll be talking with Al Swigert,
- 1:08author of Automate the Boring Stuff with Python,
- 1:11Practical Programming for Total Beginners,
- 1:13and founder of inventwithpython.com.
- 1:17This episode is brought to you by Hired and CodeChip.
- 1:20Thank them for supporting the show on Twitter via
- 1:23at Hired underscore HQ and at CodeChip.
- 1:26Now, before we get to the show,
- 1:29I do have to apologize for my audio on this one.
- 1:32The gain on my mic got bumped, and unfortunately, I didn't notice until after the interview.
- 1:37Luckily, Al's audio is great, and I let him do most of the talking, so it's not too bad,
- 1:43but the quality is definitely below the bar I try to set for this show, so I'm sorry about that.
- 1:49Now, let's get to the show.
- 1:50Let me introduce Al.
- 1:53Al Swigert is a software developer and technical book author living in San Francisco.
- 1:57Python is his favorite programming language, and he is the developer of several open source modules for it.
- 2:03His other books are freely available under the Creative Commons license on his website, inventwithpython.com.
- 2:09His cat weighs 14 pounds.
- 2:11Hey, Al. Welcome to the show.
- 2:13Hey, thanks for having me.
- 2:15You bet. You got a big cat, man.
- 2:16Oh, yes.
- 2:18In Chapter 17, which deals with image manipulation, I use a photo of her,
- 2:23and she looks especially rotund in that photo, but I have her on a diet now, so she's down to 13 pounds.
- 2:32Oh, at least it's going the right way. That's cool. I love big cats.
- 2:35Oh, yeah. I'm pretty sure she might be, like, two cats under a trench coat standing on each other's shoulders, maybe.
- 2:42That could account for the weight.
- 2:43Yeah, that's the most likely scenario, I think.
- 2:45All right. Well, welcome to the show.
- 2:48Today, we're going to be talking about your new book, Automate the Boring Stuff with Python.
- 2:52And you just released this, right?
- 2:54That's right. It came out this past April.
- 2:57I've been working on it for about a year and a half beforehand.
- 3:01And, in fact, March of 2014, I left my software developer job to start writing full-time.
- 3:07I think that's a really brave but awesome thing to do.
- 3:10Yeah. It was a calculated risk.
- 3:14I mean, for the decade beforehand, I'd always been working a safe 9-to-5 job.
- 3:19And so I had some money saved up, and so I thought, well, now's the time to start taking some risks.
- 3:25That's right. The whole learn-to-code thing is hot.
- 3:27You're probably at a place in your life where you're able to take that time and focus and so on, right?
- 3:32Yeah.
- 3:33So we're going to talk all about your book and some of the other projects that you've got going on.
- 3:38But before we get there, how did you get into programming in Python? What's your story?
- 3:42So I started programming sometime in the third grade, and I really don't like telling that story because it sort of reinforces that, like, oh, no, you have to start programming when you're a little kid or, you know, just as soon as you develop motor skills or something if you want to get good at it.
- 3:57So I always follow that up with all the programming knowledge that I gained between the third grade when I started and probably freshman year of university.
- 4:09You could probably learn that in every weekend for a few weeks.
- 4:14So it didn't really give me that much of a boost, but it was definitely something I had been interested in for a while.
- 4:21So I had started with BASIC, and I found this one book that was really great at teaching me how to program.
- 4:30And this was, you know, before Google and before you could easily find a lot of information.
- 4:36I didn't even really know that I was specifically looking up books on programming because whenever I went to the library and thought, okay, I'll just find computer books, they would just be sort of abstract and say, like, oh, this is the CPU and this is the printer and this is the keyboard and that sort of thing.
- 4:52It wouldn't actually be talking about loops and variables and other things like that.
- 4:56But this one book I found, it was great.
- 4:59It just gave me the source code for all these small little games.
- 5:02And just from that, I was able to copy that code and then make tiny adjustments to it.
- 5:08So a few years ago, a friend of mine was the nanny for this precocious 10-year-old who wanted to learn how to program.
- 5:17So I tried to find some tutorial on programming like that, but I really couldn't find anything.
- 5:23So I just started writing up a short Python tutorial, and that just eventually ballooned into book length.
- 5:29Which I just self-published.
- 5:31And people seemed to really like it.
- 5:33So I wrote a second one and then a third one.
- 5:35Now you have a habit.
- 5:36Yeah, yeah.
- 5:38I kept thinking, like, okay, this will be the last book I write.
- 5:43And then, oh, well, I got to come out of retirement to pull off one last heist.
- 5:46So that was Automate the Boring Stuff with Python.
- 5:50Yeah, that's really cool.
- 5:51What was the name of the original book?
- 5:52The original book that I found was Invent Your Own Computer Games.
- 5:58And back before I realized that this could actually become a huge book.
- 6:02So my first book was just Invent Your Own Computer Games with Python.
- 6:05And by the time it had blown up a little bit, I already was kind of stuck with that name.
- 6:11But it's worked out pretty well.
- 6:14Yeah, that's awesome.
- 6:15I think it's really inspiring to help young people kind of get started.
- 6:20It sounds like that's where your book came from.
- 6:22Yeah, it's really great to get emails from people who say, you know, like, I'm 14 years old and I want to learn how to code.
- 6:29And I essentially copied the style of that book of just having the complete source code to small programs instead of just only talking about programming concepts abstractly and then leaving it up to the reader to put all those concepts together to actually make something fun.
- 6:47Yeah, I think one of the hugest problems learning to program, and it doesn't really matter whether you're a kid or not, is in order to do anything that is at all interesting or seems like you've accomplished something, you have to learn a bunch of little tiny facts.
- 7:01Oh, yes.
- 7:02Yeah, I've got to learn what a for loop looks like.
- 7:05I've got to learn how to clear variables.
- 7:07I've got to learn how to import modules.
- 7:08And you've got to power through that stuff.
- 7:11And somehow, in your mind, you have to say there will be something good on the other side.
- 7:16And I think the kind of stuff that you're proposing gets, you know, shortens that gap.
- 7:22And so fewer people are likely to drop out, I guess.
- 7:24Yeah, I mean, I definitely tried to keep all the, in the first book, all the little game programs anywhere between 50 and 200 lines of code.
- 7:34I don't think any of the programs are more than 200 lines of code.
- 7:38Just because you don't really have to have that much code to make something a lot of fun.
- 7:42And Python is actually great about this.
- 7:44When I started writing up, like, a hangman program or a tic-tac-toe program, I realized, oh, wow, if I had written this in BASIC or in some other old programming language, this would have been probably about three or four times as long.
- 8:00And just that much more that I would have to explain in a book, and I would lose, you know, another standard deviation of readers.
- 8:07That's right.
- 8:08Here's how you import the header file, and here's how you link the static library.
- 8:12Oh, right.
- 8:12And it's like, oh, no, we're done.
- 8:13And just type out public static void main string args bracket bracket.
- 8:17We'll go into why later.
- 8:19Yeah.
- 8:20Python's great.
- 8:21Just, you know, hello world is one line.
- 8:23Yeah, Python is great.
- 8:24What I really think is cool about it is it's appropriate for this, like, my very first experience in programming.
- 8:30And as you probably know, Python is now the most popular language for first year programming courses at universities in the U.S. at least.
- 8:38Right?
- 8:39Oh, right.
- 8:40Yeah, that's awesome.
- 8:41But it's...
- 8:42It's eclipsed Java in that regard.
- 8:44Thankfully.
- 8:47And it's also appropriate for Instagram.
- 8:50And it's appropriate for discuss.
- 8:53And, like, these huge scale professional things.
- 8:58Right?
- 8:58So the fact that it's a spectrum that you don't like, okay, I'm going to learn Scratch until I want to put on my big boy pants.
- 9:03And then I've got to go learn Java.
- 9:05Right?
- 9:05It's this continuum that is wonderful, I think.
- 9:07Yeah.
- 9:09I mean, so Python, as you might know, was just based off of this language ABC, which was developed as a teaching language.
- 9:17And it turns out that making a language's syntax just easy and readable is not just good for beginners, but just a good idea in general.
- 9:25Right.
- 9:26It basically comes down to the realization that code is read way more than it's written.
- 9:30Oh, yes, definitely.
- 9:32Yeah.
- 9:32Definitely.
- 9:34So let's talk a little bit about your book and some of the topics that kind of surround it.
- 9:37Sure.
- 9:38Yeah.
- 9:40So one of the things that you said is, you know, people feel like, what's your quote, that programming is something like intimidating rocket surgery.
- 9:49And it's just scary.
- 9:51But probably it shouldn't be.
- 9:53What do you think about that?
- 9:54It's, yeah, programming definitely has that sort of, you know, you have to be a genius in order to understand this.
- 10:02And I suppose a lot of people are less intimidated by computers these days.
- 10:08Just because they're more familiar.
- 10:09Just because they're more familiar.
- 10:10But the idea that I can write software, you know, just like Mark Zuckerberg or Bill Gates can write software and go on to, you know, they, you think that you would have to be a genius in order to program a computer.
- 10:24And then that goes on to create a billion dollar company or anything like that.
- 10:29Whereas, you know, there's a wide spectrum where, oh, yeah, you could just write little scripts using some, a few programming concepts.
- 10:36And these scripts can actually be pretty useful.
- 10:39So I started thinking about, well, what kind of things could a typical office worker write?
- 10:46I mean, a lot of my non-programming friends would tell me, you know, like today at the office, I spent four hours going through a couple hundred Excel spreadsheets and copying and pasting this one line out of all of them.
- 10:59And I would think to myself, like, oh, wow, you could probably have written a script to do that in 20 minutes.
- 11:04And it would have taken about two seconds to run and you would have been finished and saved yourself an entire day of work.
- 11:10That's right.
- 11:10Not just that day, but every day going forward.
- 11:13Yeah, exactly.
- 11:14In your book, you have a cool story about some college roommates working in retail.
- 11:20Can you remember that?
- 11:21Can you tell it?
- 11:22Oh, yes.
- 11:23Yeah.
- 11:24So this story is at the very beginning of the book.
- 11:26It's one of the things that I remembered when I started writing this.
- 11:29This was, I think, my sophomore year college roommate.
- 11:35He was telling me about how he was working at this one retail outfit.
- 11:39And every once in a while, they would get a huge spreadsheet of product prices of their competitors.
- 11:47I didn't ask how they got this spreadsheet.
- 11:51But they would have to go through and type in each, you know, product SKU into their database to find their price.
- 11:58And then they would have to compare the prices.
- 12:00And they'd just mark it out on these massive printouts that they made of hundreds of pages.
- 12:06And it would be two or three of them just doing this for two days straight and going through and then just checking to see which prices they should lower in turn.
- 12:15And he said, well, you know, if you have the original file that you printed these pages out from, I could probably just write a script to go through and automatically do this.
- 12:26And, you know, so it took him like a couple hours.
- 12:29And he was just most of that was just consulting documentation and trying to remember how to do various things in C.
- 12:37But eventually he just hacked out a tiny script.
- 12:39I mean, it was basically look in this spreadsheet, look in this database, and then just see which one's higher and then print out the relevant ones to the screen.
- 12:49So, you know, after a few hours of just writing that code and he ran it and it only took a few seconds to run.
- 12:57And he basically just sort of saved everybody, you know, multiple people, a couple days of work.
- 13:02Yeah, that's fantastic.
- 13:04Yeah.
- 13:05And so computers are at this point, everybody, you know, is familiar with has access to computers.
- 13:11Lots of people have laptops.
- 13:13Lots of people have mobile phones.
- 13:16But a lot of people don't get the maximum use out of them just because they have to rely on software written by other people.
- 13:24So even if you don't want to become a software engineer, though, learning how to program will allow you to make, I don't know, turn it into a much more useful Swiss army knife that can do anything that you need it to.
- 13:37There's a lot of people out there like that.
- 13:39You know, if you're a lawyer, if you're a doctor and you run a small practice, there are all sorts of things behind the scenes that have nothing to do with lawyers or nothing to do with being doctors.
- 13:49But they have to sort of manually go through all this business-y data stuff.
- 13:52And that'd be ideal for what you're proposing, right?
- 13:55Exactly.
- 13:57Yeah.
- 13:57It's pretty good when I describe what the programming book is about.
- 14:01And it's like, oh, well, it's programming little scripts to automate tasks for people who don't want to really become software engineers.
- 14:07They just want to automate things.
- 14:09And a lot of people would tell me like, oh, yeah, that actually sounds like a great idea.
- 14:13So it was really helpful just sort of nine months into writing this.
- 14:17And I have no idea if the world needs yet another programming book or something like that.
- 14:23But it's worked out pretty well just because I think a lot of people recognize that large software companies aren't going to write software that does their particular tasks because they have such a specific workflow that's specific to their own practice or their own organization.
- 14:43But they would just need a 20-line script to do something.
- 14:47And they don't even know what it has to do until suddenly they're faced with this task.
- 14:52So just if they had those programming skills themselves, they could work it out themselves.
- 14:56Right.
- 14:57I mean, otherwise, they're probably paying thousands of dollars and hiring a consulting company.
- 15:03Or they're going to somewhere like Elance.
- 15:05And they're like, have no idea what they're getting.
- 15:08And maybe even more likely they're just not getting it done.
- 15:11Right.
- 15:12Oh, yeah.
- 15:13And once you're going to spending that large amount of money, you sort of want a large application when even that's not necessarily what you really need.
- 15:21Yeah, that's right.
- 15:23So you really stuck true to your original vision for the book in terms of how you chose topics and how you presented them and how you taught Python.
- 15:33So you threw away a lot of the traditional OO, design pattern, fancy style of programming.
- 15:40And you said, well, if you're only writing 100 lines of code, what do you really need?
- 15:44Yeah.
- 15:45This episode is brought to you by Hired.
- 15:58Hired is a two-sided, curated marketplace that connects the world's knowledge workers to the best opportunities.
- 16:05Each offer you receive has salary and equity presented right up front.
- 16:09And you can view the offers to accept or reject them before you even talk to the company.
- 16:14Typically, candidates receive five or more offers in just the first week.
- 16:18And there are no obligations ever.
- 16:20Sounds pretty awesome, doesn't it?
- 16:22Well, did I mention there's a signing bonus?
- 16:24Everyone who accepts a job from Hired gets a $2,000 signing bonus.
- 16:29And as Talk Python listeners, it gets way sweeter.
- 16:34Use the link Hired.com slash Talk Python To Me.
- 16:37And Hired will double the signing bonus to $4,000.
- 16:40Opportunity's knocking.
- 16:42Visit Hired.com slash Talk Python To Me and answer the call.
- 16:56Oh, yes, exactly.
- 16:58Like, for example, I don't go into object-oriented programming at all.
- 17:02I think I might briefly mention it at some point in the book.
- 17:06But I don't talk about classes or anything.
- 17:09I skip list comprehensions and a whole bunch of other Python nifty little features.
- 17:15Just because you really don't even need that.
- 17:18I think somewhere in the first chapter I say something like,
- 17:22well, using global variables is kind of bad once your programs get big.
- 17:26But go ahead and do it.
- 17:27You're not going to be hurting anything.
- 17:30Just to keep things really simple.
- 17:32Yeah, that makes sense.
- 17:34By the time you understand why this is a problem and you know how to fix it,
- 17:36you're going to be doing something different anyway, right?
- 17:39You may never reach that point.
- 17:40So why impose all this structure?
- 17:43I mean, that's kind of why Python and starting with Python is cool,
- 17:45is you can start easy but scale up, like I was saying,
- 17:49to these high-end, full, large-scale web apps, right?
- 17:53And so you should maybe take that same approach
- 17:55from a how-do-you-write-code perspective as well.
- 17:57Right, and I was just always sort of suspicious
- 18:00whenever I started learning a new language or something like that.
- 18:03I would go to a library or bookstore and try to find whatever books,
- 18:08and I would notice like, wow, there's 600, 700-page books on C++.
- 18:13Do I actually need to know all of this right from the start
- 18:17in order to start writing code in this?
- 18:19Yeah.
- 18:20So I really wanted something that just kept to the basic minimum.
- 18:23Yeah, and what's crazy about that C++ book
- 18:25is it was probably just the language.
- 18:27You still couldn't create a web page.
- 18:29You couldn't host a web page.
- 18:31You couldn't talk to a database.
- 18:32You couldn't show UI, nothing.
- 18:33Yeah, exactly.
- 18:34It was just a lot of syntax and maybe the reference material
- 18:38for the standard librarian.
- 18:39Yeah, but let me tell you,
- 18:41you could sure create your own operator overload at the end of that.
- 18:44But still, no window.
- 18:46Yeah, you'd have no idea why you'd want to make that.
- 18:49Yeah, exactly.
- 18:50Yeah, so I mean, a lot of those books are made for software engineers
- 18:55who already know how to program
- 18:57and sort of know all of these concepts already.
- 19:01Yeah.
- 19:02So one thing I thought was cool about your book
- 19:04is you were using Python 3.
- 19:06Yes.
- 19:07Yeah.
- 19:08Yeah, I made the switch to Python 3,
- 19:10I think about four or five years ago.
- 19:15Wow, yeah, Python 3 has been out that long.
- 19:18It has.
- 19:18Like what, 2008?
- 19:20Yeah, originally the first book I wrote was using Python 2
- 19:23and somebody recommended like,
- 19:25oh, hey, why don't you make it for Python 3?
- 19:27And I thought, oh, yeah,
- 19:28that's one of those simple and obvious things.
- 19:30So I've been working a lot with Python 3.
- 19:34At my last sort of day job,
- 19:37we were still using 2.6, I think.
- 19:41And that's just because we had a large existing code base.
- 19:43And I didn't realize how many people were still in that same boat
- 19:46until I was at PyCon recently in April of this year in Montreal.
- 19:51And I think during the keynote,
- 19:53the speaker asked the entire room of, you know,
- 19:56several hundred people,
- 19:57how many people are on Python 2
- 19:59and how many are on Python 3, just a show of hands.
- 20:02And it looked about 80% of people were just still using 2.7.
- 20:09And just like a tiny minority of the room was on Python 3,
- 20:13which was sort of astounding for me.
- 20:15So I'm very specific and particular about telling people,
- 20:19if you're going to start a new project
- 20:21or you're just learning how to code, go with Python 3.
- 20:24I mean, at this point,
- 20:26a lot of the major modules now have Python 3 support.
- 20:31So the old excuses of like,
- 20:33well, if you want to learn how to use such and such library,
- 20:37then you're just going to have to use Python 2 anyway.
- 20:39So you might as well start with that.
- 20:40So I completely recommend people picking up programming to learn Python 3.
- 20:47Yeah, that's awesome.
- 20:48And I totally agree with you.
- 20:49You know,
- 20:49I put together my website for the podcast using Pyramid and SQLAlchemy
- 20:54and various other packages,
- 20:57all Python 3,
- 20:58no harm.
- 20:58But I understand if you've got a million lines of Python 2 code,
- 21:01you might not want to go mess into that.
- 21:03So it depends whether you're new,
- 21:05whether the project is new.
- 21:06There's a lot of variables there.
- 21:07Yeah.
- 21:08Yeah.
- 21:08But I think it's cool that,
- 21:09you know,
- 21:10you're at least starting people off down that path as the default.
- 21:13And then maybe they've got to change for some reason.
- 21:15Kenneth Wright was talking about an interesting data point.
- 21:20The Django guys,
- 21:21they traditionally had their documentation in Python 2,
- 21:24and they switched it to Python 3.
- 21:26Just by switching the documentation's default view to Python 3,
- 21:30it increased the usage or something like by 4% of Python 3.
- 21:34It was like,
- 21:35wow.
- 21:35Maybe it was only for Django.
- 21:38Or it was for,
- 21:39I think it was for Python in more general.
- 21:42I have to look at the graphs again,
- 21:44but it was pretty crazy.
- 21:45Yeah.
- 21:46A tiny push in this direction.
- 21:48And I think that's a lot of the things is that Python 3 isn't,
- 21:53I mean,
- 21:54it has a lot of new and great stuff in it,
- 21:56but it isn't so completely new that it has a,
- 21:58has a lot of killer features where people are thinking,
- 22:01we must go to Python 3.
- 22:03A lot of the times people say,
- 22:05well,
- 22:05Python 2 is what we know,
- 22:06so we'll just go ahead and stick with that.
- 22:08So I think that it just needs to get that inert,
- 22:11initial inertia going.
- 22:13Yeah.
- 22:13I'd love to see some killer feature come into Python 3 only and,
- 22:16and really encourage people to switch.
- 22:18But like you said,
- 22:19I don't think we're there yet.
- 22:19Yeah.
- 22:21so one thing you do in the book that I thought was really interesting.
- 22:24And I think most programming books would absolutely skip,
- 22:28but makes such perfect sense for the audience and experience level that you're
- 22:32targeting is you actually teach people how to use Google and stack overflow to get
- 22:38programming answers.
- 22:39Yeah.
- 22:39That,
- 22:40that,
- 22:40that came from,
- 22:41uh,
- 22:41I put my email address in my,
- 22:43in my first book and I said,
- 22:44Hey,
- 22:44you should just go ahead and email me,
- 22:46uh,
- 22:47if you have questions.
- 22:48And so I would get,
- 22:49uh,
- 22:49emails from people.
- 22:51And I remember growing up,
- 22:53I had like RTFM shouted at me on an IRC channel all the time.
- 22:58And I was thinking like,
- 22:59Oh,
- 22:59that's really obnoxious and annoying.
- 23:01Um,
- 23:02but I could see the,
- 23:04the intent behind that was to make people more self-sufficient.
- 23:07Um,
- 23:08so I would get a lot of questions where people would say like,
- 23:11how do I do this?
- 23:12And I thought like,
- 23:12Oh,
- 23:12well,
- 23:13here's the terms that you can Google.
- 23:14And so at the very beginning of the book,
- 23:16I sort of wanted to help people say like,
- 23:19okay,
- 23:19so programming might be hard at times,
- 23:22but you can always just Google for,
- 23:24you know,
- 23:25if you get some error message,
- 23:26which will never make sense whatsoever,
- 23:28like,
- 23:28uh,
- 23:29the common example I use is if you forget to put the ending quote on a string,
- 23:34the error message isn't,
- 23:36you forgot to put a quote,
- 23:37uh,
- 23:38to end the string.
- 23:38It's,
- 23:39it's something like E all,
- 23:41uh,
- 23:41syntax error at unterminated string or something like that.
- 23:45And you have no idea,
- 23:46like,
- 23:47even if you're a native English speaker,
- 23:48you have no idea what that means.
- 23:50So I just wanted to say,
- 23:51look,
- 23:51it's okay.
- 23:52You can just copy and paste that entire message into Google and you'll find a bunch of websites where people
- 23:58have had this exact same problem.
- 24:00Uh,
- 24:00the top three results will probably be stack overflow.
- 24:03Uh,
- 24:04and then they can just learn of like,
- 24:05oh,
- 24:05there's a site stack overflow and I can ask questions there.
- 24:08Um,
- 24:09especially because after a while I noticed people would be emailing me the same questions.
- 24:14So I thought,
- 24:14oh,
- 24:15well,
- 24:15it's not really efficient for me to individually send out this answer each time.
- 24:19So making people more self,
- 24:21uh,
- 24:22self-sufficient in finding answers for themselves,
- 24:24I thought was something I wanted to have right at the start of the book.
- 24:27Yeah,
- 24:28that's really cool.
- 24:29And you know,
- 24:29it's as programmers,
- 24:31we know that you can put insane stuff in and search for it.
- 24:35But when you were learning,
- 24:37you know,
- 24:37you don't necessarily know you can just put like an error code or other bizarre stuff into Google and get insanely detailed answers.
- 24:43Yeah.
- 24:44Yeah.
- 24:44one time I had a friend who had,
- 24:46um,
- 24:46outlook,
- 24:47like small business edition match with some weird thing on windows.
- 24:51And it like went crazy and lost all of his email.
- 24:54And he said,
- 24:55I know you're not really into this,
- 24:56but I know you know computers.
- 24:58Well,
- 24:58cause you just look at this and help me.
- 25:00I'm like,
- 25:00geez,
- 25:01I don't mean I'm not an outlook person.
- 25:02I don't really know,
- 25:03but it came up and said,
- 25:05you know,
- 25:06error,
- 25:06OX,
- 25:07that had some huge,
- 25:08long hexadecimal error code or something.
- 25:11So I just typed outlook and that thing into Google and bam,
- 25:14there was the exact steps to fix the problem.
- 25:16And I'm like,
- 25:17look,
- 25:17just what you can do.
- 25:18Just,
- 25:18and he's like,
- 25:19how is this even possible?
- 25:20Right.
- 25:20It's just,
- 25:21you know,
- 25:21we take it for granted,
- 25:22but I think it's cool that you show people how to do that.
- 25:24Cause it's surprisingly effective.
- 25:26Yeah.
- 25:27I mean,
- 25:27I had a friend,
- 25:28uh,
- 25:29she wasn't a programmer,
- 25:30but she worked at a biotech startup and wasn't,
- 25:34uh,
- 25:34there as in an IT role or anything like that,
- 25:36but she effectively became this small company's IT department.
- 25:40I think because she was the only person who wasn't afraid to just Google how to do stuff.
- 25:45Whereas everybody else was just like amazed and thought she was really great at computers or something.
- 25:49It's like,
- 25:49no,
- 25:49she can just sit down and she's not afraid to say,
- 25:52you know,
- 25:53Google for SharePoint server set up and just do all the,
- 25:57yeah,
- 25:57follow all the steps.
- 25:58Yeah.
- 25:58That's awesome.
- 25:59I,
- 25:59one of,
- 25:59there was some study done that said,
- 26:01you know,
- 26:01what is the most important,
- 26:02uh,
- 26:03personality trait for successful startup founders?
- 26:07And,
- 26:07and basically for people creating companies and what was the most tech companies in particular.
- 26:12And it turned out the most important thing was simply persistence,
- 26:15not being super smart or whatever.
- 26:16Right.
- 26:17Right.
- 26:17Just having that tenacity.
- 26:19Yeah.
- 26:19And this is part of it.
- 26:20Like,
- 26:20I'm just going to keep searching,
- 26:21keep digging until I get there and just being effective.
- 26:24That's cool.
- 26:25Another thing that you have in a lot of the sections is you've got like practice questions
- 26:30and you've got even challenges.
- 26:31So that's really nice to have some hands-on component.
- 26:34Yeah.
- 26:35I didn't have those in the first couple of books I wrote and I kept getting emails from
- 26:40people who said like,
- 26:41Oh,
- 26:41it'd be great if I had practice questions.
- 26:43I always thought that was just something that,
- 26:44you know,
- 26:45was,
- 26:45was sort of just filler and nobody actually really followed through with those.
- 26:49I remember whenever I read programming books,
- 26:51I would kind of like,
- 26:52you know,
- 26:53answer a few of them maybe,
- 26:54or sometimes I'd just skip them.
- 26:56But a lot of people started thinking like,
- 26:59Oh yeah,
- 26:59it'd be great to have those practice questions.
- 27:01And also I would get teachers and professors saying,
- 27:04Oh yeah,
- 27:05I love your book.
- 27:05It's great.
- 27:06I'm using it for,
- 27:07for this course,
- 27:08but there's no practice questions or,
- 27:10or any exam material or things like that.
- 27:13It'd be great if,
- 27:14if a book had that.
- 27:15So that really opened my eyes to just how many people could,
- 27:18could find this information useful.
- 27:22And also I,
- 27:23I wanted to sort of keep focus on having the,
- 27:26the source code to actual programs,
- 27:28um,
- 27:29and not just have this be a laundry list of programming concepts that,
- 27:33that I just,
- 27:34you know,
- 27:35Oh,
- 27:35these are loops.
- 27:35These are variables.
- 27:36These are functions.
- 27:37Uh,
- 27:38and,
- 27:39and have it as just that I wanted to have actual complete programs as well that
- 27:43people could,
- 27:43could see.
- 27:44Yeah,
- 27:45that's great.
- 27:45Do you have your,
- 27:46uh,
- 27:46finished examples and programs on something like GitHub?
- 27:50Uh,
- 27:50they're on the no starch.com,
- 27:52uh,
- 27:53slash automate stuff website.
- 27:54Okay.
- 27:55Uh,
- 27:55there's a link there.
- 27:56It says like,
- 27:57here's the zip files for,
- 27:58for all the,
- 27:59all the programs and things.
- 28:00That's cool.
- 28:00So people can go download them.
- 28:02Yeah.
- 28:02Yeah.
- 28:03Nice.
- 28:04so we talked a little bit about why you chose Python over other languages,
- 28:09but there,
- 28:10there's certainly,
- 28:11it seems like there might be some trade-offs.
- 28:12Like,
- 28:13suppose you want to do that work with Excel.
- 28:15I know if maybe you chose something like.net,
- 28:17you could use like the,
- 28:18the calm integration on windows to directly integrate with Excel and stuff like,
- 28:24you know,
- 28:25what,
- 28:25what were your,
- 28:26what was your thought process of choosing Python over the other various things?
- 28:30I,
- 28:31to be honest,
- 28:32I really didn't spend that much time thinking about it.
- 28:35Uh,
- 28:35mostly because Python was,
- 28:36was such an obvious,
- 28:38uh,
- 28:38first language to learn.
- 28:40It has a,
- 28:41it has such a great learning curve,
- 28:43um,
- 28:43that I thought,
- 28:44well,
- 28:45everything else I can just kind of figure out after that,
- 28:48because I didn't want to choose,
- 28:50go with a different language just because it would make some other things easier.
- 28:56I thought,
- 28:56well,
- 28:56Python's great.
- 28:57It's,
- 28:58uh,
- 28:58it's mostly the same.
- 29:00if you have windows or a Mac.
- 29:02Yeah.
- 29:03The cross platform part of it's really nice.
- 29:05So,
- 29:05yeah.
- 29:05And,
- 29:06and it turns out there's,
- 29:07there's plenty of modules for doing things like working with Excel spreadsheets and reading
- 29:11word documents.
- 29:12Uh,
- 29:13yeah,
- 29:13that was actually a little surprising to me because I've never tried to work with Excel
- 29:16from a Python,
- 29:17but it sounds pretty easy.
- 29:18Maybe you could talk a little bit about the,
- 29:19uh,
- 29:20the second half or second segment of your book.
- 29:22So the first half is all about,
- 29:24here's how you get started with programming.
- 29:25Here's like loops and in a really approachable way,
- 29:27but then you get into like,
- 29:29let's automate some things.
- 29:30Can you talk about some of the things?
- 29:46This episode is brought to you by code ship.
- 29:48Code ship has launched organizations,
- 29:51create teams,
- 29:52set permissions for specific team members and improve collaboration in your continuous delivery
- 29:57workflow.
- 29:57Maintain centralized control of your organization's projects and teams with code chips,
- 30:02new organizations plan.
- 30:03And as talk Python listeners,
- 30:05you can save 20% off any premium plan for the next three months.
- 30:08Just use the code talk Python,
- 30:11all caps,
- 30:11no spaces.
- 30:12Check them out at code ship.com and tell them.
- 30:15Thanks for supporting the show on Twitter,
- 30:16where they're at code chip.
- 30:23Yeah.
- 30:24I mean,
- 30:24I wanted the book to be for complete beginners.
- 30:27So I have that first part of the book,
- 30:28which is assuming you don't know anything about programming whatsoever,
- 30:32but I thought,
- 30:32well,
- 30:33it'd be nice to actually have like in the second part,
- 30:36go into all these different third party modules that make doing all these different tasks easier.
- 30:42So there's,
- 30:43there's a chapter on web scraping using Selenium and beautiful soup and requests.
- 30:48And,
- 30:49and then also another chapter on using OpenPy Excel to work with Excel spreadsheets and things like that.
- 30:56I was really surprised at how many modules were out there that,
- 31:00that were actually pretty high quality and projects that I hadn't really heard of before until I started looking for them.
- 31:07And so a lot of the,
- 31:08a lot of the initial work of writing out this book,
- 31:12was just going through and mapping out,
- 31:13okay,
- 31:14what are the problems that have to be solved?
- 31:15What modules are available out there?
- 31:17And Python is,
- 31:18is pretty well supported in that regard.
- 31:20Yeah,
- 31:20I think you're right.
- 31:21I think the whole PyPI package stuff,
- 31:24I mean,
- 31:25there's 56,
- 31:2657,000 of those,
- 31:27right?
- 31:28A lot of them.
- 31:28Yeah.
- 31:29Yeah.
- 31:29And it's,
- 31:30it's great.
- 31:30There was the whole XKCD cartoon about Python where he just typed import anti-gravity and you,
- 31:38that kind of,
- 31:38that kind of sums it up,
- 31:39right?
- 31:39Yeah.
- 31:41Yeah.
- 31:41there's the,
- 31:42the concept in,
- 31:43in a lot of the Python documentation of Guido's time machine where Guido Van Rossum,
- 31:48the creator of Python would commonly reply to email lists when people said like,
- 31:53I'd really need a module to do such and such.
- 31:56And he would reply like,
- 31:57oh yeah,
- 31:58I just committed a module that did that last night,
- 32:00leading a lot of people to think that he actually has a time machine and can start writing these code,
- 32:05this code before you even think of it.
- 32:07Yeah.
- 32:08That's awesome.
- 32:09You've got this book.
- 32:10You have your two other books.
- 32:11You also said you've done a couple of open source projects or packages for Python.
- 32:15Do you want to speak about that a little?
- 32:17Yeah.
- 32:19What became the most popular of them so far is,
- 32:22is one that I actually wrote for the book.
- 32:24It was for chapter 18 on,
- 32:26on controlling the keyboard and mouse.
- 32:28I found a lot of code out there that,
- 32:30well,
- 32:31I wanted a module that first worked on Python 2 and 3 and also worked equally well on Windows,
- 32:39Mac,
- 32:39and Linux.
- 32:39And so I would find a lot of great modules,
- 32:42except,
- 32:42you know,
- 32:43some of them would only be for Python 2,
- 32:45or some of them would only be for a particular operating system.
- 32:49or sometimes the API was,
- 32:51just had a bunch of odd names for things.
- 32:53So I wanted something really simple.
- 32:54So I created PyAuto GUI,
- 32:57which gets a few thousand downloads each month now,
- 33:01and especially now that the book is out and covers it.
- 33:04But it was basically just taking all the best parts of code from all these various modules
- 33:08and putting them into this unified interface.
- 33:12So you have,
- 33:13and it's really simple.
- 33:14You just import the module and it has a click function or a typewrite function to just type out an entire string.
- 33:22Or if you want to press down certain keys,
- 33:24those are all just single functions.
- 33:26So I really like that.
- 33:27Before I had started writing this automate book,
- 33:30my second book was on PyGame.
- 33:33And so I'd written a few modules for that,
- 33:36which one,
- 33:37which was PigCurse,
- 33:39which is sort of a curses emulator,
- 33:42except built on top of PyGame.
- 33:44And that was just so that I could have some way of writing text to a certain cell.
- 33:49Like I could tell the cursor to go to some XY position and then start typing out things like that.
- 33:55Just because again,
- 33:57you know,
- 33:58Python has curses,
- 33:59but then for Windows,
- 34:00there's a separate console module
- 34:02that you would have to install.
- 34:04So there's no unified thing that just works on all operating systems.
- 34:09And then also,
- 34:10there was a PigAnim,
- 34:13which is a sprite animation module that I made for PyGame.
- 34:17Nice.
- 34:17For building like 2D,
- 34:18little side scroller apps,
- 34:20that kind of thing.
- 34:22Yeah,
- 34:22well,
- 34:22it's basically just to be able to take like an animated GIF and put it into your program.
- 34:28I mean,
- 34:28PyGame is great because it would make it really easy just to display an image in a window somewhere.
- 34:33But if you wanted to have,
- 34:35you know,
- 34:35a little like animation of a running character or something like that,
- 34:39you would have to program all that logic in yourself because PyGame was fairly bare bones.
- 34:45And I looked around and I saw that nobody else had made something like this in particular for PyGame.
- 34:51So I just started that as like a week long project.
- 34:53And I've written a few other modules,
- 34:55but,
- 34:55you know,
- 34:56they're all just really tiny and just have like,
- 34:58you know,
- 34:58a hundred downloads a month on PyPI.
- 35:00But yeah,
- 35:02just a lot of really simple things.
- 35:03Yeah,
- 35:04that's really great.
- 35:05All right.
- 35:05Albert,
- 35:06I think this might be a good place to wrap it up.
- 35:09But before I let you go,
- 35:10let me ask you a few questions that I typically ask people on the way out.
- 35:14In addition to PyAuto GUI,
- 35:17what other PyPI packages are your favorite or most useful or you think,
- 35:21you know,
- 35:21people maybe don't know about you should tell them about?
- 35:23Oh,
- 35:24I think really at the top of that is Selenium.
- 35:27The web scraping chapter on the book's website,
- 35:32I think the web scraping chapter is the most popular one.
- 35:36And so Selenium basically launches Firefox or,
- 35:41or a different browser and lets you programmatically control it.
- 35:44So you could just automate doing web scraping or filling out forms or anything like that.
- 35:50And I'd heard of Selenium and other things before,
- 35:53but I always thought like,
- 35:55oh,
- 35:55it must be this really complicated thing that you have to,
- 35:58you know,
- 35:58spend an entire weekend reading up on.
- 36:01I didn't realize,
- 36:02oh,
- 36:02actually,
- 36:02no,
- 36:02it's about,
- 36:03you know,
- 36:03four or five different functions that you have to learn.
- 36:06And then you can pretty much,
- 36:07and then you're set after that.
- 36:08So Selenium is,
- 36:10is definitely one of my,
- 36:11it's,
- 36:12I'm completely amazed at how much you can do with it,
- 36:15even with,
- 36:16you know,
- 36:17a very little knowledge and very little time learning about it.
- 36:20Yeah.
- 36:21That's awesome.
- 36:21It seems like you could almost do like basic load testing,
- 36:25integration testing,
- 36:26other types of sort of web automation with it,
- 36:29right?
- 36:30Oh yeah,
- 36:30exactly.
- 36:31I mean,
- 36:31because it's actually launching a,
- 36:33a web browser,
- 36:35you can have it work with whatever browser plugins you have,
- 36:40or it'll run JavaScript on the page.
- 36:42So,
- 36:43you know,
- 36:43it's not just downloading files from a URL.
- 36:46You can actually simulate the JavaScript as well,
- 36:49and then see how it looks like for the,
- 36:52for the user.
- 36:52It's,
- 36:53it's a really great module.
- 36:54Yeah.
- 36:54That's excellent.
- 36:55Yeah.
- 36:55Make all those,
- 36:56uh,
- 36:56client side spa type apps actually show what they're supposed to show.
- 37:00Right.
- 37:00Yeah.
- 37:02Nice.
- 37:03Okay.
- 37:04Uh,
- 37:04next one.
- 37:05Uh,
- 37:05are you,
- 37:05what kind of editor are you using these days?
- 37:08Uh,
- 37:09I really like sublime text.
- 37:11Um,
- 37:11I mean,
- 37:12for the longest time I use this one text editor called edit text,
- 37:16which was sort of like notepad plus plus.
- 37:20Well,
- 37:21not like there is actually an editor called notepad plus,
- 37:24plus,
- 37:24but it was all the things,
- 37:25uh,
- 37:26I'm on windows.
- 37:27It was all the things of notepad.exe,
- 37:29except it had a light,
- 37:30a lot of other nice features,
- 37:32but it was still fairly lightweight.
- 37:33I've never actually gotten around to learning,
- 37:36uh,
- 37:36Vim or Emacs to any great extent where,
- 37:40you know,
- 37:40I can sit down and use them,
- 37:41but I,
- 37:42I think I like using the mouse too much.
- 37:45Yeah.
- 37:45Yeah.
- 37:46I hear you.
- 37:46Okay,
- 37:47cool.
- 37:47Yeah.
- 37:48I like sublime as well.
- 37:49It's really nice.
- 37:49Yeah.
- 37:50And in the book,
- 37:51I just say,
- 37:52go ahead and use idle.
- 37:53Um,
- 37:53because it just comes with Python if you're on windows.
- 37:56And so you don't have to,
- 37:57you would have to do any setup or configuration,
- 37:59which is really nice.
- 38:01Yeah.
- 38:01That is great.
- 38:02And it's all,
- 38:02it's all about reducing the friction and getting people to like have those moments of,
- 38:05Hey,
- 38:06I've created something rather than why do I care about how to declare a string?
- 38:10Yeah,
- 38:10exactly.
- 38:11That's awesome.
- 38:12Okay.
- 38:13So what,
- 38:14what do you want to give a final shout out to let everybody know about your book,
- 38:18obviously?
- 38:18Oh yes,
- 38:20definitely the book.
- 38:20Uh,
- 38:21it's released under a creative commons license,
- 38:23so you can actually read it online at automate the boring stuff.com.
- 38:27Um,
- 38:27but also I'd like to just encourage people to go ahead and make it out to PyCon.
- 38:32It's,
- 38:33it's a really great conference.
- 38:34Uh,
- 38:35you don't have to be a heavy technical person to,
- 38:38to get a lot of benefit out of.
- 38:40And the people in the community are really wonderful.
- 38:42Yeah,
- 38:43that's awesome.
- 38:44I would like to second that as well.
- 38:45And this year it's in Portland,
- 38:46Oregon,
- 38:47which is my hometown.
- 38:48And so that's pretty awesome.
- 38:49And I'm trying to get together a,
- 38:52some kind of session.
- 38:53That's like a,
- 38:54a panel discussion,
- 38:55live podcast presentation.
- 38:57So maybe I'll be able to pull that off.
- 38:59That'd be fun.
- 38:59Oh yeah,
- 39:00that sounds great.
- 39:01Yeah.
- 39:01People should definitely come to it.
- 39:03It'll be great.
- 39:03And then I also want to encourage people to go check out your book and maybe even buy it,
- 39:08right?
- 39:08Like you,
- 39:09you've done some really cool stuff.
- 39:10Yeah.
- 39:10And it is available,
- 39:12you know,
- 39:12sort of separate pages as HTML and you can check it out,
- 39:15but you know,
- 39:16it's not that much.
- 39:18So support the work.
- 39:19Yeah.
- 39:20A lot of people really like having it all combined on their Kindle or just having the physical book in their hand.
- 39:25Right.
- 39:25Absolutely.
- 39:26All right,
- 39:27Al,
- 39:27thanks for being on the show.
- 39:29It's been fun.
- 39:29Oh,
- 39:30thanks.
- 39:30Yeah.
- 39:31It's been a lot of fun for me too.
- 39:32Yeah.
- 39:32Bye.
- 39:33Today's guest was Al Swigert.
- 39:36And this episode has been sponsored by Hired and CodeGip.
- 39:39Thank you guys for supporting the show.
- 39:41Hired wants you to find your next big thing.
- 39:44Visit Hired.com slash Talk Python To Me and get five or more offers with salary and equity presented right up front and a special listener signing bonus of $4,000.
- 39:56CodeGip wants you to always keep shipping.
- 39:58Check them out at CodeGip.com and thank them on Twitter via at CodeGip.
- 40:03And don't forget the discount code for listeners.
- 40:05It's easy.
- 40:06Talk Python.
- 40:07All caps.
- 40:07No spaces.
- 40:09You can find the links from today's show at Talk Python To Me.com slash episodes slash show slash 19.
- 40:16While you're at it,
- 40:17be sure to subscribe to the show.
- 40:19Open your favorite podcatcher and search for Python.
- 40:21We should be right at the top.
- 40:23You can also find the iTunes and direct RSS feeds in the footer of the website.
- 40:29Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 40:34You can hear the entire song on our website.
- 40:36This is your host, Michael Kennedy.
- 40:38Thanks for listening.
- 40:40Smix takes us out of here.
- 40:51We'll see you next time.
- 41:01We'll see you next time.
- 41:03First of all, first of all, first of all, first of all, first of all, first of all.