Learn Python with Talk Python's 270 hours of courses

#19: Automate the Boring Stuff with Python Transcript

Recorded on Thursday, Jul 2, 2015.

00:00 You know, some of the things we do in life are tedious and boring.

00:03 They're the kind of things that machines or maybe robots could do.

00:07 So let's build those machines.

00:09 This is Talk Python, and we'll be automating the boring stuff with Al Swigert.

00:13 It's show number 19, recorded Thursday, July 2nd, 2015.

00:18 Hello, and welcome to Talk Python to Me, a weekly podcast on Python.

00:48 The language, the libraries, the ecosystem, and the personalities.

00:51 This is your host, Michael Kennedy.

00:53 Follow me on Twitter, where I'm @mkennedy, and keep up with the show and listen to past episodes at talkpythontimmy.com.

01:00 Also, follow the show on Twitter, where it's at Talk Python.

01:04 This episode, we'll be talking with Al Swigert, author of Automate the Boring Stuff with Python,

01:11 Practical Programming for Total Beginners, and founder of inventwithpython.com.

01:17 This episode is brought to you by Hired and CodeChip.

01:20 Thank them for supporting the show on Twitter via at Hired underscore HQ and at CodeChip.

01:26 Now, before we get to the show, I do have to apologize for my audio on this one.

01:32 The gain on my mic got bumped, and unfortunately, I didn't notice until after the interview.

01:37 Luckily, Al's audio is great, and I let him do most of the talking, so it's not too bad,

01:43 but the quality is definitely below the bar I try to set for this show, so I'm sorry about that.

01:49 Now, let's get to the show.

01:50 Let me introduce Al.

01:53 Al Swigert is a software developer and technical book author living in San Francisco.

01:57 Python is his favorite programming language, and he is the developer of several open source modules for it.

02:03 His other books are freely available under the Creative Commons license on his website, inventwithpython.com.

02:09 His cat weighs 14 pounds.

02:11 Hey, Al. Welcome to the show.

02:13 Hey, thanks for having me.

02:15 You bet. You got a big cat, man.

02:16 Oh, yes.

02:18 In Chapter 17, which deals with image manipulation, I use a photo of her,

02:23 and she looks especially rotund in that photo, but I have her on a diet now, so she's down to 13 pounds.

02:32 Oh, at least it's going the right way. That's cool. I love big cats.

02:35 Oh, yeah. I'm pretty sure she might be, like, two cats under a trench coat standing on each other's shoulders, maybe.

02:42 That could account for the weight.

02:43 Yeah, that's the most likely scenario, I think.

02:45 All right. Well, welcome to the show.

02:48 Today, we're going to be talking about your new book, Automate the Boring Stuff with Python.

02:52 And you just released this, right?

02:54 That's right. It came out this past April.

02:57 I've been working on it for about a year and a half beforehand.

03:01 And, in fact, March of 2014, I left my software developer job to start writing full-time.

03:07 I think that's a really brave but awesome thing to do.

03:10 Yeah. It was a calculated risk.

03:14 I mean, for the decade beforehand, I'd always been working a safe 9-to-5 job.

03:19 And so I had some money saved up, and so I thought, well, now's the time to start taking some risks.

03:25 That's right. The whole learn-to-code thing is hot.

03:27 You're probably at a place in your life where you're able to take that time and focus and so on, right?

03:32 Yeah.

03:33 So we're going to talk all about your book and some of the other projects that you've got going on.

03:38 But before we get there, how did you get into programming in Python? What's your story?

03:42 So 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.

03:57 So 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.

04:09 You could probably learn that in every weekend for a few weeks.

04:14 So it didn't really give me that much of a boost, but it was definitely something I had been interested in for a while.

04:21 So I had started with BASIC, and I found this one book that was really great at teaching me how to program.

04:30 And this was, you know, before Google and before you could easily find a lot of information.

04:36 I 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.

04:52 It wouldn't actually be talking about loops and variables and other things like that.

04:56 But this one book I found, it was great.

04:59 It just gave me the source code for all these small little games.

05:02 And just from that, I was able to copy that code and then make tiny adjustments to it.

05:08 So a few years ago, a friend of mine was the nanny for this precocious 10-year-old who wanted to learn how to program.

05:17 So I tried to find some tutorial on programming like that, but I really couldn't find anything.

05:23 So I just started writing up a short Python tutorial, and that just eventually ballooned into book length.

05:29 Which I just self-published.

05:31 And people seemed to really like it.

05:33 So I wrote a second one and then a third one.

05:35 Now you have a habit.

05:36 Yeah, yeah.

05:38 I kept thinking, like, okay, this will be the last book I write.

05:43 And then, oh, well, I got to come out of retirement to pull off one last heist.

05:46 So that was Automate the Boring Stuff with Python.

05:50 Yeah, that's really cool.

05:51 What was the name of the original book?

05:52 The original book that I found was Invent Your Own Computer Games.

05:58 And back before I realized that this could actually become a huge book.

06:02 So my first book was just Invent Your Own Computer Games with Python.

06:05 And by the time it had blown up a little bit, I already was kind of stuck with that name.

06:11 But it's worked out pretty well.

06:14 Yeah, that's awesome.

06:15 I think it's really inspiring to help young people kind of get started.

06:20 It sounds like that's where your book came from.

06:22 Yeah, 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.

06:29 And 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.

06:47 Yeah, 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.

07:01 Oh, yes.

07:02 Yeah, I've got to learn what a for loop looks like.

07:05 I've got to learn how to clear variables.

07:07 I've got to learn how to import modules.

07:08 And you've got to power through that stuff.

07:11 And somehow, in your mind, you have to say there will be something good on the other side.

07:16 And I think the kind of stuff that you're proposing gets, you know, shortens that gap.

07:22 And so fewer people are likely to drop out, I guess.

07:24 Yeah, 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.

07:34 I don't think any of the programs are more than 200 lines of code.

07:38 Just because you don't really have to have that much code to make something a lot of fun.

07:42 And Python is actually great about this.

07:44 When 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.

08:00 And just that much more that I would have to explain in a book, and I would lose, you know, another standard deviation of readers.

08:07 That's right.

08:08 Here's how you import the header file, and here's how you link the static library.

08:12 Oh, right.

08:12 And it's like, oh, no, we're done.

08:13 And just type out public static void main string args bracket bracket.

08:17 We'll go into why later.

08:19 Yeah.

08:20 Python's great.

08:21 Just, you know, hello world is one line.

08:23 Yeah, Python is great.

08:24 What I really think is cool about it is it's appropriate for this, like, my very first experience in programming.

08:30 And as you probably know, Python is now the most popular language for first year programming courses at universities in the U.S. at least.

08:38 Right?

08:39 Oh, right.

08:40 Yeah, that's awesome.

08:41 But it's...

08:42 It's eclipsed Java in that regard.

08:44 Thankfully.

08:47 And it's also appropriate for Instagram.

08:50 And it's appropriate for discuss.

08:53 And, like, these huge scale professional things.

08:58 Right?

08:58 So 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.

09:03 And then I've got to go learn Java.

09:05 Right?

09:05 It's this continuum that is wonderful, I think.

09:07 Yeah.

09:09 I mean, so Python, as you might know, was just based off of this language ABC, which was developed as a teaching language.

09:17 And 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.

09:25 Right.

09:26 It basically comes down to the realization that code is read way more than it's written.

09:30 Oh, yes, definitely.

09:32 Yeah.

09:32 Definitely.

09:34 So let's talk a little bit about your book and some of the topics that kind of surround it.

09:37 Sure.

09:38 Yeah.

09:40 So 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.

09:49 And it's just scary.

09:51 But probably it shouldn't be.

09:53 What do you think about that?

09:54 It's, yeah, programming definitely has that sort of, you know, you have to be a genius in order to understand this.

10:02 And I suppose a lot of people are less intimidated by computers these days.

10:08 Just because they're more familiar.

10:09 Just because they're more familiar.

10:10 But 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:24 And then that goes on to create a billion dollar company or anything like that.

10:29 Whereas, you know, there's a wide spectrum where, oh, yeah, you could just write little scripts using some, a few programming concepts.

10:36 And these scripts can actually be pretty useful.

10:39 So I started thinking about, well, what kind of things could a typical office worker write?

10:46 I 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:59 And I would think to myself, like, oh, wow, you could probably have written a script to do that in 20 minutes.

11:04 And it would have taken about two seconds to run and you would have been finished and saved yourself an entire day of work.

11:10 That's right.

11:10 Not just that day, but every day going forward.

11:13 Yeah, exactly.

11:14 In your book, you have a cool story about some college roommates working in retail.

11:20 Can you remember that?

11:21 Can you tell it?

11:22 Oh, yes.

11:23 Yeah.

11:24 So this story is at the very beginning of the book.

11:26 It's one of the things that I remembered when I started writing this.

11:29 This was, I think, my sophomore year college roommate.

11:35 He was telling me about how he was working at this one retail outfit.

11:39 And every once in a while, they would get a huge spreadsheet of product prices of their competitors.

11:47 I didn't ask how they got this spreadsheet.

11:51 But they would have to go through and type in each, you know, product SKU into their database to find their price.

11:58 And then they would have to compare the prices.

12:00 And they'd just mark it out on these massive printouts that they made of hundreds of pages.

12:06 And 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:15 And 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:26 And, you know, so it took him like a couple hours.

12:29 And he was just most of that was just consulting documentation and trying to remember how to do various things in C.

12:37 But eventually he just hacked out a tiny script.

12:39 I 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:49 So, 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:57 And he basically just sort of saved everybody, you know, multiple people, a couple days of work.

13:02 Yeah, that's fantastic.

13:04 Yeah.

13:05 And so computers are at this point, everybody, you know, is familiar with has access to computers.

13:11 Lots of people have laptops.

13:13 Lots of people have mobile phones.

13:16 But 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:24 So 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:37 There's a lot of people out there like that.

13:39 You 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:49 But they have to sort of manually go through all this business-y data stuff.

13:52 And that'd be ideal for what you're proposing, right?

13:55 Exactly.

13:57 Yeah.

13:57 It's pretty good when I describe what the programming book is about.

14:01 And 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:07 They just want to automate things.

14:09 And a lot of people would tell me like, oh, yeah, that actually sounds like a great idea.

14:13 So it was really helpful just sort of nine months into writing this.

14:17 And I have no idea if the world needs yet another programming book or something like that.

14:23 But 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:43 But they would just need a 20-line script to do something.

14:47 And they don't even know what it has to do until suddenly they're faced with this task.

14:52 So just if they had those programming skills themselves, they could work it out themselves.

14:56 Right.

14:57 I mean, otherwise, they're probably paying thousands of dollars and hiring a consulting company.

15:03 Or they're going to somewhere like Elance.

15:05 And they're like, have no idea what they're getting.

15:08 And maybe even more likely they're just not getting it done.

15:11 Right.

15:12 Oh, yeah.

15:13 And 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:21 Yeah, that's right.

15:23 So 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:33 So you threw away a lot of the traditional OO, design pattern, fancy style of programming.

15:40 And you said, well, if you're only writing 100 lines of code, what do you really need?

15:44 Yeah.

15:45 This episode is brought to you by Hired.

15:58 Hired is a two-sided, curated marketplace that connects the world's knowledge workers to the best opportunities.

16:05 Each offer you receive has salary and equity presented right up front.

16:09 And you can view the offers to accept or reject them before you even talk to the company.

16:14 Typically, candidates receive five or more offers in just the first week.

16:18 And there are no obligations ever.

16:20 Sounds pretty awesome, doesn't it?

16:22 Well, did I mention there's a signing bonus?

16:24 Everyone who accepts a job from Hired gets a $2,000 signing bonus.

16:29 And as Talk Python listeners, it gets way sweeter.

16:34 Use the link Hired.com slash Talk Python to me.

16:37 And Hired will double the signing bonus to $4,000.

16:40 Opportunity's knocking.

16:42 Visit Hired.com slash Talk Python to me and answer the call.

16:56 Oh, yes, exactly.

16:58 Like, for example, I don't go into object-oriented programming at all.

17:02 I think I might briefly mention it at some point in the book.

17:06 But I don't talk about classes or anything.

17:09 I skip list comprehensions and a whole bunch of other Python nifty little features.

17:15 Just because you really don't even need that.

17:18 I think somewhere in the first chapter I say something like, well, using global variables is kind of bad once your programs get big.

17:26 But go ahead and do it.

17:27 You're not going to be hurting anything.

17:30 Just to keep things really simple.

17:32 Yeah, that makes sense.

17:34 By the time you understand why this is a problem and you know how to fix it,

17:36 you're going to be doing something different anyway, right?

17:39 You may never reach that point.

17:40 So why impose all this structure?

17:43 I mean, that's kind of why Python and starting with Python is cool, is you can start easy but scale up, like I was saying,

17:49 to these high-end, full, large-scale web apps, right?

17:53 And so you should maybe take that same approach from a how-do-you-write-code perspective as well.

17:57 Right, and I was just always sort of suspicious whenever I started learning a new language or something like that.

18:03 I would go to a library or bookstore and try to find whatever books, and I would notice like, wow, there's 600, 700-page books on C++.

18:13 Do I actually need to know all of this right from the start in order to start writing code in this?

18:19 Yeah.

18:20 So I really wanted something that just kept to the basic minimum.

18:23 Yeah, and what's crazy about that C++ book is it was probably just the language.

18:27 You still couldn't create a web page.

18:29 You couldn't host a web page.

18:31 You couldn't talk to a database.

18:32 You couldn't show UI, nothing.

18:33 Yeah, exactly.

18:34 It was just a lot of syntax and maybe the reference material for the standard librarian.

18:39 Yeah, but let me tell you, you could sure create your own operator overload at the end of that.

18:44 But still, no window.

18:46 Yeah, you'd have no idea why you'd want to make that.

18:49 Yeah, exactly.

18:50 Yeah, so I mean, a lot of those books are made for software engineers who already know how to program

18:57 and sort of know all of these concepts already.

19:01 Yeah.

19:02 So one thing I thought was cool about your book is you were using Python 3.

19:06 Yes.

19:07 Yeah.

19:08 Yeah, I made the switch to Python 3, I think about four or five years ago.

19:15 Wow, yeah, Python 3 has been out that long.

19:18 It has.

19:18 Like what, 2008?

19:20 Yeah, originally the first book I wrote was using Python 2 and somebody recommended like,

19:25 oh, hey, why don't you make it for Python 3?

19:27 And I thought, oh, yeah, that's one of those simple and obvious things.

19:30 So I've been working a lot with Python 3.

19:34 At my last sort of day job, we were still using 2.6, I think.

19:41 And that's just because we had a large existing code base.

19:43 And I didn't realize how many people were still in that same boat until I was at PyCon recently in April of this year in Montreal.

19:51 And I think during the keynote, the speaker asked the entire room of, you know,

19:56 several hundred people, how many people are on Python 2 and how many are on Python 3, just a show of hands.

20:02 And it looked about 80% of people were just still using 2.7.

20:09 And just like a tiny minority of the room was on Python 3, which was sort of astounding for me.

20:15 So I'm very specific and particular about telling people, if you're going to start a new project

20:21 or you're just learning how to code, go with Python 3.

20:24 I mean, at this point, a lot of the major modules now have Python 3 support.

20:31 So the old excuses of like, well, if you want to learn how to use such and such library,

20:37 then you're just going to have to use Python 2 anyway.

20:39 So you might as well start with that.

20:40 So I completely recommend people picking up programming to learn Python 3.

20:47 Yeah, that's awesome.

20:48 And I totally agree with you.

20:49 You know, I put together my website for the podcast using Pyramid and SQLAlchemy

20:54 and various other packages, all Python 3, no harm.

20:58 But I understand if you've got a million lines of Python 2 code, you might not want to go mess into that.

21:03 So it depends whether you're new, whether the project is new.

21:06 There's a lot of variables there.

21:07 Yeah.

21:08 Yeah.

21:08 But I think it's cool that, you know, you're at least starting people off down that path as the default.

21:13 And then maybe they've got to change for some reason.

21:15 Kenneth Wright was talking about an interesting data point.

21:20 The Django guys, they traditionally had their documentation in Python 2,

21:24 and they switched it to Python 3.

21:26 Just by switching the documentation's default view to Python 3, it increased the usage or something like by 4% of Python 3.

21:34 It was like, wow.

21:35 Maybe it was only for Django.

21:38 Or it was for, I think it was for Python in more general.

21:42 I have to look at the graphs again, but it was pretty crazy.

21:45 Yeah.

21:46 A tiny push in this direction.

21:48 And I think that's a lot of the things is that Python 3 isn't, I mean, it has a lot of new and great stuff in it,

21:56 but it isn't so completely new that it has a, has a lot of killer features where people are thinking,

22:01 we must go to Python 3.

22:03 A lot of the times people say, well, Python 2 is what we know, so we'll just go ahead and stick with that.

22:08 So I think that it just needs to get that inert, initial inertia going.

22:13 Yeah.

22:13 I'd love to see some killer feature come into Python 3 only and, and really encourage people to switch.

22:18 But like you said, I don't think we're there yet.

22:19 Yeah.

22:21 so one thing you do in the book that I thought was really interesting.

22:24 And I think most programming books would absolutely skip, but makes such perfect sense for the audience and experience level that you're

22:32 targeting is you actually teach people how to use Google and stack overflow to get

22:38 programming answers.

22:39 Yeah.

22:39 That, that, that came from, I put my email address in my, in my first book and I said,

22:44 Hey, you should just go ahead and email me, if you have questions.

22:48 And so I would get, emails from people.

22:51 And I remember growing up, I had like RTFM shouted at me on an IRC channel all the time.

22:58 And I was thinking like, Oh, that's really obnoxious and annoying.

23:01 but I could see the, the intent behind that was to make people more self-sufficient.

23:07 so I would get a lot of questions where people would say like, how do I do this?

23:12 And I thought like, Oh, well, here's the terms that you can Google.

23:14 And so at the very beginning of the book, I sort of wanted to help people say like,

23:19 okay, so programming might be hard at times, but you can always just Google for,

23:24 you know, if you get some error message, which will never make sense whatsoever,

23:28 like, the common example I use is if you forget to put the ending quote on a string,

23:34 the error message isn't, you forgot to put a quote, to end the string.

23:38 It's, it's something like E all, syntax error at unterminated string or something like that.

23:45 And you have no idea, like, even if you're a native English speaker, you have no idea what that means.

23:50 So I just wanted to say, look, it's okay.

23:52 You can just copy and paste that entire message into Google and you'll find a bunch of websites where people

23:58 have had this exact same problem.

24:00 the top three results will probably be stack overflow.

24:03 and then they can just learn of like, oh, there's a site stack overflow and I can ask questions there.

24:08 especially because after a while I noticed people would be emailing me the same questions.

24:14 So I thought, oh, well, it's not really efficient for me to individually send out this answer each time.

24:19 So making people more self, self-sufficient in finding answers for themselves,

24:24 I thought was something I wanted to have right at the start of the book.

24:27 Yeah, that's really cool.

24:29 And you know, it's as programmers, we know that you can put insane stuff in and search for it.

24:35 But when you were learning, you know, you don't necessarily know you can just put like an error code or other bizarre stuff into Google and get insanely detailed answers.

24:43 Yeah.

24:44 Yeah.

24:44 one time I had a friend who had, outlook, like small business edition match with some weird thing on windows.

24:51 And it like went crazy and lost all of his email.

24:54 And he said, I know you're not really into this, but I know you know computers.

24:58 Well, cause you just look at this and help me.

25:00 I'm like, geez, I don't mean I'm not an outlook person.

25:02 I don't really know, but it came up and said, you know, error, OX, that had some huge,

25:08 long hexadecimal error code or something.

25:11 So I just typed outlook and that thing into Google and bam, there was the exact steps to fix the problem.

25:16 And I'm like, look, just what you can do.

25:18 Just, and he's like, how is this even possible?

25:20 Right.

25:20 It's just, you know, we take it for granted, but I think it's cool that you show people how to do that.

25:24 Cause it's surprisingly effective.

25:26 Yeah.

25:27 I mean, I had a friend, she wasn't a programmer, but she worked at a biotech startup and wasn't,

25:34 there as in an IT role or anything like that, but she effectively became this small company's IT department.

25:40 I think because she was the only person who wasn't afraid to just Google how to do stuff.

25:45 Whereas everybody else was just like amazed and thought she was really great at computers or something.

25:49 It's like, no, she can just sit down and she's not afraid to say, you know,

25:53 Google for SharePoint server set up and just do all the, yeah, follow all the steps.

25:58 Yeah.

25:58 That's awesome.

25:59 I, one of, there was some study done that said, you know, what is the most important,

26:02 personality trait for successful startup founders?

26:07 And, and basically for people creating companies and what was the most tech companies in particular.

26:12 And it turned out the most important thing was simply persistence, not being super smart or whatever.

26:16 Right.

26:17 Right.

26:17 Just having that tenacity.

26:19 Yeah.

26:19 And this is part of it.

26:20 Like, I'm just going to keep searching, keep digging until I get there and just being effective.

26:24 That's cool.

26:25 Another thing that you have in a lot of the sections is you've got like practice questions

26:30 and you've got even challenges.

26:31 So that's really nice to have some hands-on component.

26:34 Yeah.

26:35 I didn't have those in the first couple of books I wrote and I kept getting emails from

26:40 people who said like, Oh, it'd be great if I had practice questions.

26:43 I always thought that was just something that, you know, was, was sort of just filler and nobody actually really followed through with those.

26:49 I remember whenever I read programming books, I would kind of like, you know,

26:53 answer a few of them maybe, or sometimes I'd just skip them.

26:56 But a lot of people started thinking like, Oh yeah, it'd be great to have those practice questions.

27:01 And also I would get teachers and professors saying, Oh yeah, I love your book.

27:05 It's great.

27:06 I'm using it for, for this course, but there's no practice questions or,

27:10 or any exam material or things like that.

27:13 It'd be great if, if a book had that.

27:15 So that really opened my eyes to just how many people could, could find this information useful.

27:22 And also I, I wanted to sort of keep focus on having the, the source code to actual programs,

27:28 and not just have this be a laundry list of programming concepts that, that I just,

27:34 you know, Oh, these are loops.

27:35 These are variables.

27:36 These are functions.

27:37 and, and have it as just that I wanted to have actual complete programs as well that

27:43 people could, could see.

27:44 Yeah, that's great.

27:45 Do you have your, finished examples and programs on something like GitHub?

27:50 they're on the no starch.com, slash automate stuff website.

27:54 Okay.

27:55 there's a link there.

27:56 It says like, here's the zip files for, for all the, all the programs and things.

28:00 That's cool.

28:00 So people can go download them.

28:02 Yeah.

28:02 Yeah.

28:03 Nice.

28:04 so we talked a little bit about why you chose Python over other languages,

28:09 but there, there's certainly, it seems like there might be some trade-offs.

28:12 Like, suppose you want to do that work with Excel.

28:15 I know if maybe you chose something like.net, you could use like the, the calm integration on windows to directly integrate with Excel and stuff like,

28:24 you know, what, what were your, what was your thought process of choosing Python over the other various things?

28:30 I, to be honest, I really didn't spend that much time thinking about it.

28:35 mostly because Python was, was such an obvious, first language to learn.

28:40 It has a, it has such a great learning curve, that I thought, well, everything else I can just kind of figure out after that,

28:48 because I didn't want to choose, go with a different language just because it would make some other things easier.

28:56 I thought, well, Python's great.

28:57 It's, it's mostly the same.

29:00 if you have windows or a Mac.

29:02 Yeah.

29:03 The cross platform part of it's really nice.

29:05 So, yeah.

29:05 And, and it turns out there's, there's plenty of modules for doing things like working with Excel spreadsheets and reading

29:11 word documents.

29:12 yeah, that was actually a little surprising to me because I've never tried to work with Excel

29:16 from a Python, but it sounds pretty easy.

29:18 Maybe you could talk a little bit about the, the second half or second segment of your book.

29:22 So the first half is all about, here's how you get started with programming.

29:25 Here's like loops and in a really approachable way, but then you get into like,

29:29 let's automate some things.

29:30 Can you talk about some of the things?

29:46 This episode is brought to you by code ship.

29:48 Code ship has launched organizations, create teams, set permissions for specific team members and improve collaboration in your continuous delivery

29:57 workflow.

29:57 Maintain centralized control of your organization's projects and teams with code chips,

30:02 new organizations plan.

30:03 And as talk Python listeners, you can save 20% off any premium plan for the next three months.

30:08 Just use the code talk Python, all caps, no spaces.

30:12 Check them out at code ship.com and tell them.

30:15 Thanks for supporting the show on Twitter, where they're at code chip.

30:23 Yeah.

30:24 I mean, I wanted the book to be for complete beginners.

30:27 So I have that first part of the book, which is assuming you don't know anything about programming whatsoever,

30:32 but I thought, well, it'd be nice to actually have like in the second part,

30:36 go into all these different third party modules that make doing all these different tasks easier.

30:42 So there's, there's a chapter on web scraping using Selenium and beautiful soup and requests.

30:48 And, and then also another chapter on using OpenPy Excel to work with Excel spreadsheets and things like that.

30:56 I was really surprised at how many modules were out there that, that were actually pretty high quality and projects that I hadn't really heard of before until I started looking for them.

31:07 And so a lot of the, a lot of the initial work of writing out this book,

31:12 was just going through and mapping out, okay, what are the problems that have to be solved?

31:15 What modules are available out there?

31:17 And Python is, is pretty well supported in that regard.

31:20 Yeah, I think you're right.

31:21 I think the whole PyPI package stuff, I mean, there's 56, 57,000 of those,

31:27 right?

31:28 A lot of them.

31:28 Yeah.

31:29 Yeah.

31:29 And it's, it's great.

31:30 There was the whole XKCD cartoon about Python where he just typed import anti-gravity and you,

31:38 that kind of, that kind of sums it up, right?

31:39 Yeah.

31:41 Yeah.

31:41 there's the, the concept in, in a lot of the Python documentation of Guido's time machine where Guido Van Rossum,

31:48 the creator of Python would commonly reply to email lists when people said like,

31:53 I'd really need a module to do such and such.

31:56 And he would reply like, oh yeah, I just committed a module that did that last night,

32:00 leading a lot of people to think that he actually has a time machine and can start writing these code,

32:05 this code before you even think of it.

32:07 Yeah.

32:08 That's awesome.

32:09 You've got this book.

32:10 You have your two other books.

32:11 You also said you've done a couple of open source projects or packages for Python.

32:15 Do you want to speak about that a little?

32:17 Yeah.

32:19 What became the most popular of them so far is, is one that I actually wrote for the book.

32:24 It was for chapter 18 on, on controlling the keyboard and mouse.

32:28 I found a lot of code out there that, well, I wanted a module that first worked on Python 2 and 3 and also worked equally well on Windows,

32:39 Mac, and Linux.

32:39 And so I would find a lot of great modules, except, you know, some of them would only be for Python 2,

32:45 or some of them would only be for a particular operating system.

32:49 or sometimes the API was, just had a bunch of odd names for things.

32:53 So I wanted something really simple.

32:54 So I created PyAuto GUI, which gets a few thousand downloads each month now,

33:01 and especially now that the book is out and covers it.

33:04 But it was basically just taking all the best parts of code from all these various modules

33:08 and putting them into this unified interface.

33:12 So you have, and it's really simple.

33:14 You just import the module and it has a click function or a typewrite function to just type out an entire string.

33:22 Or if you want to press down certain keys, those are all just single functions.

33:26 So I really like that.

33:27 Before I had started writing this automate book, my second book was on PyGame.

33:33 And so I'd written a few modules for that, which one, which was PigCurse,

33:39 which is sort of a curses emulator, except built on top of PyGame.

33:44 And that was just so that I could have some way of writing text to a certain cell.

33:49 Like I could tell the cursor to go to some XY position and then start typing out things like that.

33:55 Just because again, you know, Python has curses, but then for Windows, there's a separate console module

34:02 that you would have to install.

34:04 So there's no unified thing that just works on all operating systems.

34:09 And then also, there was a PigAnim, which is a sprite animation module that I made for PyGame.

34:17 Nice.

34:17 For building like 2D, little side scroller apps, that kind of thing.

34:22 Yeah, well, it's basically just to be able to take like an animated GIF and put it into your program.

34:28 I mean, PyGame is great because it would make it really easy just to display an image in a window somewhere.

34:33 But if you wanted to have, you know, a little like animation of a running character or something like that,

34:39 you would have to program all that logic in yourself because PyGame was fairly bare bones.

34:45 And I looked around and I saw that nobody else had made something like this in particular for PyGame.

34:51 So I just started that as like a week long project.

34:53 And I've written a few other modules, but, you know, they're all just really tiny and just have like,

34:58 you know, a hundred downloads a month on PyPI.

35:00 But yeah, just a lot of really simple things.

35:03 Yeah, that's really great.

35:05 All right.

35:05 Albert, I think this might be a good place to wrap it up.

35:09 But before I let you go, let me ask you a few questions that I typically ask people on the way out.

35:14 In addition to PyAuto GUI, what other PyPI packages are your favorite or most useful or you think,

35:21 you know, people maybe don't know about you should tell them about?

35:23 Oh, I think really at the top of that is Selenium.

35:27 The web scraping chapter on the book's website, I think the web scraping chapter is the most popular one.

35:36 And so Selenium basically launches Firefox or, or a different browser and lets you programmatically control it.

35:44 So you could just automate doing web scraping or filling out forms or anything like that.

35:50 And I'd heard of Selenium and other things before, but I always thought like,

35:55 oh, it must be this really complicated thing that you have to, you know,

35:58 spend an entire weekend reading up on.

36:01 I didn't realize, oh, actually, no, it's about, you know, four or five different functions that you have to learn.

36:06 And then you can pretty much, and then you're set after that.

36:08 So Selenium is, is definitely one of my, it's, I'm completely amazed at how much you can do with it,

36:15 even with, you know, a very little knowledge and very little time learning about it.

36:20 Yeah.

36:21 That's awesome.

36:21 It seems like you could almost do like basic load testing, integration testing,

36:26 other types of sort of web automation with it, right?

36:30 Oh yeah, exactly.

36:31 I mean, because it's actually launching a, a web browser, you can have it work with whatever browser plugins you have,

36:40 or it'll run JavaScript on the page.

36:42 So, you know, it's not just downloading files from a URL.

36:46 You can actually simulate the JavaScript as well, and then see how it looks like for the,

36:52 for the user.

36:52 It's, it's a really great module.

36:54 Yeah.

36:54 That's excellent.

36:55 Yeah.

36:55 Make all those, client side spa type apps actually show what they're supposed to show.

37:00 Right.

37:00 Yeah.

37:02 Nice.

37:03 Okay.

37:04 next one.

37:05 are you, what kind of editor are you using these days?

37:08 I really like sublime text.

37:11 I mean, for the longest time I use this one text editor called edit text,

37:16 which was sort of like notepad plus plus.

37:20 Well, not like there is actually an editor called notepad plus, plus, but it was all the things,

37:25 I'm on windows.

37:27 It was all the things of notepad.exe, except it had a light, a lot of other nice features,

37:32 but it was still fairly lightweight.

37:33 I've never actually gotten around to learning, Vim or Emacs to any great extent where,

37:40 you know, I can sit down and use them, but I, I think I like using the mouse too much.

37:45 Yeah.

37:45 Yeah.

37:46 I hear you.

37:46 Okay, cool.

37:47 Yeah.

37:48 I like sublime as well.

37:49 It's really nice.

37:49 Yeah.

37:50 And in the book, I just say, go ahead and use idle.

37:53 because it just comes with Python if you're on windows.

37:56 And so you don't have to, you would have to do any setup or configuration,

37:59 which is really nice.

38:01 Yeah.

38:01 That is great.

38:02 And it's all, it's all about reducing the friction and getting people to like have those moments of,

38:05 Hey, I've created something rather than why do I care about how to declare a string?

38:10 Yeah, exactly.

38:11 That's awesome.

38:12 Okay.

38:13 So what, what do you want to give a final shout out to let everybody know about your book,

38:18 obviously?

38:18 Oh yes, definitely the book.

38:20 it's released under a creative commons license, so you can actually read it online at automate the boring stuff.com.

38:27 but also I'd like to just encourage people to go ahead and make it out to PyCon.

38:32 It's, it's a really great conference.

38:34 you don't have to be a heavy technical person to, to get a lot of benefit out of.

38:40 And the people in the community are really wonderful.

38:42 Yeah, that's awesome.

38:44 I would like to second that as well.

38:45 And this year it's in Portland, Oregon, which is my hometown.

38:48 And so that's pretty awesome.

38:49 And I'm trying to get together a, some kind of session.

38:53 That's like a, a panel discussion, live podcast presentation.

38:57 So maybe I'll be able to pull that off.

38:59 That'd be fun.

38:59 Oh yeah, that sounds great.

39:01 Yeah.

39:01 People should definitely come to it.

39:03 It'll be great.

39:03 And then I also want to encourage people to go check out your book and maybe even buy it,

39:08 right?

39:08 Like you, you've done some really cool stuff.

39:10 Yeah.

39:10 And it is available, you know, sort of separate pages as HTML and you can check it out,

39:15 but you know, it's not that much.

39:18 So support the work.

39:19 Yeah.

39:20 A lot of people really like having it all combined on their Kindle or just having the physical book in their hand.

39:25 Right.

39:25 Absolutely.

39:26 All right, Al, thanks for being on the show.

39:29 It's been fun.

39:29 Oh, thanks.

39:30 Yeah.

39:31 It's been a lot of fun for me too.

39:32 Yeah.

39:32 Bye.

39:33 Today's guest was Al Swigert.

39:36 And this episode has been sponsored by Hired and CodeGip.

39:39 Thank you guys for supporting the show.

39:41 Hired wants you to find your next big thing.

39:44 Visit 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:56 CodeGip wants you to always keep shipping.

39:58 Check them out at CodeGip.com and thank them on Twitter via at CodeGip.

40:03 And don't forget the discount code for listeners.

40:05 It's easy.

40:06 Talk Python.

40:07 All caps.

40:07 No spaces.

40:09 You can find the links from today's show at Talk Python to me.com slash episodes slash show slash 19.

40:16 While you're at it, be sure to subscribe to the show.

40:19 Open your favorite podcatcher and search for Python.

40:21 We should be right at the top.

40:23 You can also find the iTunes and direct RSS feeds in the footer of the website.

40:29 Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.

40:34 You can hear the entire song on our website.

40:36 This is your host, Michael Kennedy.

40:38 Thanks for listening.

40:40 Smix takes us out of here.

40:51 We'll see you next time.

41:01 We'll see you next time.

41:03 First of all, first of all, first of all, first of all, first of all, first of all.

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon