Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book


Transcript #6: Python 3.6 is going to be awesome, Kite: your friendly co-developing AI

Return to episode page view on github
Recorded on Monday, Dec 12, 2016.

00:00 This is Python Bytes. Python headlines and news delivered directly to your earbuds.

00:03 It's episode six, recorded Monday, December 12th. This episode is brought to you by Rollbar.

00:09 They help take the pain out of errors. Thank you so much, Rollbar, for sponsoring the show.

00:13 And this is Michael Kennedy, one of your hosts. I'm here with Brian Okken, my co-host. Hello,

00:18 Brian. How's it going, man? Hello. It's going really good. Good, good. This year's gone by

00:23 quickly, hasn't it? It's gone. It's super fast. Yeah, I feel like everyone was fixated on the

00:29 election because it was so unique. And then kind of nobody knows what to do with the rest of the year.

00:34 So I'm going to go on vacation. How about you? I'm going to start writing. So yeah, you got a book

00:41 to finish, man. Anyway, so the point is, this is actually our last episode of the year. So I want

00:46 to say thanks to everybody who subscribed and listened and shared this podcast with their friends.

00:51 We're taking a break and we will be back first thing in January, first week. We'll have even more

00:58 share, won't we? Yeah, that'll be the, I have like three weeks of stuff to catch up on.

01:02 Yeah. Hopefully no drama. Okay. So what's the first item you want to share with everyone? What'd you

01:07 find? Well, there's an article by Dan Bader, make your Python code more readable with custom

01:12 exception classes. This is great. He wrote up a little tutorial along with a five minute video where

01:19 he walks through stuff. He talks about the, including your own exception classes can make your errors

01:25 more readable within your code and also communicate to the users of your functions or whatever your

01:32 intent and what the errors are. And also you can add more context. I like it because it's one of those

01:36 things that I was afraid to add custom exceptions and it's really just pretty darn easy. The main

01:43 points I think is to remember to derive from either exception or one of the other built-in Python

01:47 exceptions. Like value error or something like that, right? Yeah. Whatever sort of makes sense.

01:53 And, and it's a, it's a good one. I also wanted to add that if you are, there's extra things you

01:59 should do if you're releasing a package and, or even within, within your company, I think it's good to

02:06 derive from your own, create a custom exception and then derive all your other exceptions from that one.

02:11 And I got that tip from another article that we'll link to in the show notes by Julian Danju.

02:17 Yeah. Yeah. Yeah. That's a really great point actually, because it would be great to do try,

02:22 accept all of the errors from this package. Like whatever's happening in here, I want to start by

02:27 handling those and maybe get more specific ones. Maybe not, but yeah, I hadn't really thought about

02:34 that. The make your own special base exception. Even the reverse, try to do specific first and then,

02:41 and then do a catch all of those. And then if it isn't one of your package ones, then you can also

02:47 still catch the general exception and do something different there. Yeah, that's cool. There's two,

02:51 there's a couple of things about this article. I like when Dan Bader is doing a bunch of cool videos

02:56 on YouTube, he really seems to be putting a lot of effort to frequently get those out. And so here's an

03:01 article that takes like five minutes to read, but there's also a five minute video screencast to go

03:05 along with it. So well done on that, Dan. And then more generally, this idea here, it makes it easier

03:12 for one of my favorite programming patterns, which is also quite Pythonic is in that it's, the pattern is

03:18 it's easier to ask for forgiveness than permission, as opposed to like the C++ style, look before you leap

03:24 programming model where you test the heck out of everything and then you try a thing. You just, here, you just do it.

03:28 If there was an exception, you know, you catch it and then accept block and it's all good.

03:32 Yeah. I definitely like a, at a high level, like for instance, if I were, as an example, if I were using

03:39 requests, I could have a special handler that dealt with exceptions from requests and know that, that I,

03:46 cause I understand what part of my system's dealing with that. I could handle it in one place.

03:51 Right. Absolutely. Yeah. Could not contact server. The web service seems to be down.

03:55 Something like this, right? Beautiful. Wouldn't it be awesome if like artificial intelligence could just

04:01 like sit there and just like help you code? I mean, we all know of AI for like Siri and silly things like

04:08 that. But I feel like actually 2016 is a little bit where the future kind of intersected with now.

04:14 Like things became the future came to us. There are so many things with AI that are really awesome.

04:19 Like there was several AIs that actually on their own invented encryption. But what I want is an AI to

04:25 help me as a developer. How about you? Sounds great. Yeah. That'd be super cool. So, so I actually ran

04:30 across this thing. one of the listeners, Gilberto Diaz was nice enough to send me a link and,

04:35 an email say, Hey, there's this thing that is so cool. You must check it out. It's not technically

04:40 built in Python, but it really supports Python developers in a crazy good way. So there's this

04:46 thing called kite at kite.com and it's in private beta. We were lucky enough to get some early access

04:51 to it. And what it is, is like you install it in your OS and it sits in kind of like a sidebar.

04:56 It takes up maybe like, I don't know, a fifth of your screen. If you have two screens and, you know,

05:00 stick it on the other one and it watches what you do in all sorts of different programming

05:06 environments in sublime text and Visual Studio Code in PyCharm, even Vim or Emacs has many,

05:12 many plugins. As you type, it helps you. All right. So, if you're writing Python code and you type

05:20 import space, it'll show you a list of the most popular packages. If you type R, it'll show you the

05:25 list of the most popular packages that start with R like request right at the top. Yeah. And then once

05:30 you import a thing, it'll start showing you documentation about it. Here's some examples

05:34 on how to use that thing you just imported as you start to like, you know, interact with it,

05:37 like request dot, it'll say, well, the most commonly called function here is get, you want to see some

05:41 examples, how to use request dot get or like the documentation. And it just, it just really is quite

05:48 cool how much it knows. And you know, it does auto completion. Like many editors do it'll, it'll like

05:55 show you on the left, like, here's the things you can complete. But what I like about it is it uses like

05:59 crowdsourcing for popularity. So there's like, you know, 10,000, developers working on this.

06:06 And they'll say, well, this is the most popular completion in this situation here.

06:10 Base, not just alphabetical or something. So I think it's cool. There's, there's a great video

06:14 you have to watch. If you go check this out at kite.com, it's like right there in the homepage.

06:18 I'm, I'm looking forward to playing with it. Yeah. You, you'd mentioned it seems like AI pair programming

06:24 and, does sure sound like that. It's, it's quite interesting. I feel like it's more like a

06:29 artificial intelligence mentor rather than paired programmer. Like it's there going, oh, by the way,

06:34 did you know that the, you actually can call this function? Oh, that package is really cool. Cause

06:38 it has this thing you might not know about. It's kind of like the wiser, wiser version rather than like,

06:43 you know, pair programmer, but I think it's great.

06:45 Oh, definitely looking forward to trying that.

06:47 Yeah, for sure. I hate it when my data gets messy.

06:50 Yeah, definitely. so there, there's an article, by, I'm going to even try this

06:56 Jean Nicholas hold, I think tidy data in Python. This article was pretty interesting. It caught my

07:02 attention because I often have data that's in a format that I can't use right away and I need to

07:08 transform it into something else. And I, I didn't ever think of it like, changing tables around and,

07:14 and completely changing things automatically. Anyway, this article gives some, some attributes

07:20 of what problems to look at in data sets. He based it on a paper named tidy data by Hadley Wickham.

07:27 He takes the idea of the paper and then transfers it to, into Python and how to, how to utilize it

07:35 in Python with the pandas library. And like, so this seems very abstract right now, but he has some

07:42 examples of, data that's, that's really data is in the column headers. He has some attributes to

07:48 look for, like each variable forms a column and contains a value and each observation forms a row

07:55 and the type of observation units form a table. And it still sounds kind of complex or kind of abstract,

08:03 but the examples really are pretty easy to follow. And I, it's just a neat idea of, of taking a look at

08:10 your data and making it more useful. I had never really thought about data in this sense,

08:14 but it seems to me like this talks about how you put your data together so that you'll be,

08:19 it's most natural to take advantage of it with things like pandas and the various data science tools

08:26 and all sorts of languages, but he's focused on Python, which is extra cool.

08:30 And so he's, he has several examples on, on, you know, do things this way, not that way. And your life will be

08:36 much easier. And I just never thought of systemizing that, I guess.

08:39 Yeah. And I also, looking at the different comparison of before and after tables, you can

08:45 definitely see how it's definitely the, the converted table is easier programmatically, but the from table,

08:52 the, the dirty one is, it's, it's more broken up, like how people look at stuff. I didn't think there

09:00 would be a difference, but it does appear to be, it's, it's easier for, to visualize smaller tables

09:06 as people, but, as computers, we need things a little bit more broken down.

09:10 Yeah, it's cool. So if you've got a lot of data, especially in tabular form, check that out.

09:13 We're going on break. Like I'm actually heading out on vacation somewhere away from home and,

09:19 you know, I'm still taking my laptop with me because that would be kind of insane. But you know,

09:23 our sponsor roll bar, they, they were going to let me just chill out and not worry about whether the

09:29 web app is working and not check it all the time. Like I might not use my computer for a few days.

09:33 And unless I get notifications on my phone or, you know, text messages or slack or something like

09:38 that saying, Hey, your website's down. There's this problem. You know, things are going to be good.

09:42 I'm not going to worry about it. That's because I got roll bar integrated with all the talk Python

09:45 stuff, which is really cool. So if there's a problem, you know, I can just read what the error is and

09:50 probably fix it pretty easily. So all the Python byte listeners, they can have the

09:53 same peace of mind. They just have to go to rollbar.com/pythonbytes and sign up for the

09:57 free tier. Sounds cool, huh? Sounds very good. Yeah. Yeah. It's good. It's good to be on vacation

10:02 and you know, not worry about things working. Just set up the error notifications and you're all good.

10:06 I'm really excited that there's a new version of Python. I'm, I think people are starting to move

10:13 on from legacy Python and there's just end of this week, there's going to be one more reason to do so.

10:18 So we actually have as our next item, a video, a conference presentation at PyCon Canada

10:23 2016 by Brett Cannon. He did a talk called what's new in Python three. And I think it's interesting.

10:32 You look at all the peps and all the stuff that's coming and you think, well, okay,

10:35 they're doing little tweaks here. I guess it has new string formatting and whatever. It turns out

10:39 there are over 16 peps in Python three, six, and that's more than any peps that have been in Python

10:45 three other than the actual creation of Python 3.0 itself. That's pretty cool, right?

10:50 Maybe we should have had another role before now then maybe, but I'm excited for all these.

10:56 Yeah, it's going to be great. It's going to be great. The reason I like this video and I want to

11:00 point it out is we could all go to, you know, what's new in Python three and we can read the list. Like,

11:05 okay, well here dictionaries will be ordered. there's now a private identifier or like a versioning

11:11 number on dictionaries. Like, okay, whatever, who cares? This gives you the story behind all the

11:15 changes coming to Python three, six, right? Why did the core developers of which Brett is one

11:20 think that this is a good idea? Like, how does it help? What, what really problem, what problem are

11:26 they really trying to solve deep down when they made this change? And it really is a cool look inside

11:32 what's coming with Python three, six. that sounds great.

11:35 I think it's, it's good. So Python three, six release candidates available right now if you want to

11:40 download it, but you know, if you can wait like five days, you should have the final version of

11:44 Python three, six. They did something with virtual environments, right?

11:47 Yeah. This is one of the things I, I was stumbled across. I think it was in a Reddit line somewhere,

11:53 the command command line command of pyvenv, which I can't remember which version that came in on one of

12:00 the three O's that's being deprecated. And the reason, and they want people to use the dash M V E N V

12:07 instead. And that's so that you specifically tell the virtual environment system, which Python to use.

12:15 And it makes the programmer know, need to know how to get to Python first before they create a virtual

12:21 environment. I think that it totally makes sense. It's just something to point out. I think it's

12:26 important. It I'm going to have to actually edit my book because of this, because, I think I, I

12:31 recommended pyvenv in mine. So time to un-recommend it. Yeah. that's cool. No, I do think it is good.

12:39 I mean, you can say Python three --version, you'll see what that is. And then you can say Python

12:44 three dash M V and V, and then that's the thing you're going to get. Right. So it is a little more

12:48 clear, I guess. Very cool. Yeah. It wouldn't be a week in Python without some form of testing or code

12:53 coverage, right? Yeah, definitely. And, Ned Batchelder, who we all owe some gratitude for,

12:59 for coming up with, or for taking over the coverage package. He's, I interviewed him

13:05 about that on episode 12 of testing code, but, he's planning a new feature for coverage up high,

13:11 which will tell us which, so when you, when you run a coverage report, also what functions cause

13:18 this, or, or how did you get this stuff covered? And, he covers it in an article. He taught,

13:24 he titled, who tests what this is a discussion about kind of, how I like the discussion because

13:31 those, those people new to coverage can kind of peek inside and see the different stages of how

13:37 coverage works. It goes through measurement and storing the data and then combining the data

13:42 and reporting because you can't have multiple tests, most multiple runs and combine them into

13:47 it to one report. This idea of, trying to figure out which code was covered by which tests

13:53 is how it started, but he comes up with some, some reasons why there may be more, more uses than just

14:00 in testing. And it's a, it's a good discussion, but part of one of the things he, why he wrote this

14:06 article is, is to try to get some help. He wants some feedback. So some of the questions are,

14:11 he discusses the memory, memory usage and, and the data model. And he wants to know if there's

14:17 something we need more sophisticated problem solving on this, or should we be more conservative with

14:23 memory? And then the output, the output right now is intended to be in Jason, but he wants to know if

14:29 somebody could use a different data format. I like the direction he's going with it. And I think

14:33 I'll use it and I encourage anybody that has sort of a non-standard usage of coverage to take a look

14:39 at this article and give Ned some feedback. Yeah. I really like it as well, because a lot of times,

14:44 unless you're actually a contributor to the project already, you feel like the fate of the thing is

14:50 already determined, but this was much more like, look, we have this challenging problem. these are the

14:55 ways and the trade-offs were thinking about the ways we're thinking about solving it. The trade-offs were

14:59 contemplating. We're not sure where to go. If you want to help, here's how to help. If you want to

15:03 give us feedback before we jump in and go the wrong direction, do it. So this is a really cool article

15:08 just on philosophy as well. Yeah. I think it's great. And being able to know which tests actually

15:13 triggered the covered line when you run a thousand tests with these three, like that's pretty interesting.

15:18 Yeah. And you know, before I talked to him, I didn't realize that there was, there were so many

15:23 features of coverage that I didn't realize, like being able to have multiple test runs and combine

15:27 that data and HTML output and things like that. It's pretty cool. Yeah. Yeah. Quite cool. Quite cool.

15:33 So what do you got for us, Michael? All right. I've got one, one final glorious topic for the rest of the

15:39 year to round out 2016. So here it is, threaded asynchronous magic and how to wield it. So this is a

15:46 really cool article by Christian Medina. You know, we had talked about the, I don't remember exactly

15:52 the title, but that asyncio tutorial, that was like the G event tutorial remade for asyncio and Python

15:59 three, four. And we're like, well, wouldn't it be cool if there's a great one on async and await,

16:02 like the really, the, the truly new cool features of Python for threading and parallelism. Well, Christian

16:09 Medina wrote it. Awesome. He wrote a really nice one and it has a bunch of bite-sized examples. You can,

16:16 you know, they're not too, they're not too large, but they don't seem entirely fake.

16:20 So he has one example of like sending email notifications, sort of asynchronously, but it's

16:26 like, you know, but you realize there's no awaitable asynchronous, like way to send mail in Python. So,

16:31 well, we're just going to block, but at least we can use this asyncio loop for that. That's cool.

16:36 And then also talked about the AIO HTTP library, which is an HTTP client server for asyncio and how to do a

16:44 bunch of parallel web requests. So we often think about requests being the primary way that we do

16:50 programming against web services and generally HTTP. But this is another option that's really simple,

16:56 that fits exactly into the asyncio. So you can easily block on the network calls, which will then free

17:03 up the thread to go do other stuff because it knows it's waiting on the network. That sounds cool.

17:06 Yeah, it's really cool. It covers things like tasks, scheduling tasks, scatter, gather styles of

17:12 programming, and then even moving the asyncio loop to a background thread. So you don't block up your

17:17 main thread, but you kind of have a place to put all the asynchronous work and let it run on that other

17:22 one thread, which is pretty cool. So yeah. So thanks, Christian, for doing that. Got to meet him at

17:27 PyCon last year. And so that was fun. And hopefully everyone else is going to PyCon. If you don't have your tickets yet,

17:34 you need to be getting it, right, Brian? Definitely. I missed out last year. So.

17:38 Don't be sad. Get tickets before they sell out because this, I'm sure it will sell out. It sold

17:43 out early last year. Plus it's in Portland and Portland rocks. Portland definitely rocks. It's

17:48 going to be weird. They're going to be keeping it weird. All right. Well, that's it for me. I don't

17:54 really have a whole lot of news to share other than just saying thanks to everyone for listening,

17:57 you know, for our new podcast. It's been fun to do for you and I appreciate all the feedback.

18:03 I appreciate it too. Speaking of feedback, we did get one person. I think it's Harry J.

18:08 I hope I didn't pronounce that wrong. On Twitter said that he listened to episode three and I had

18:14 mentioned that a library called Pianini that don't know if I'm pronouncing that right, but I assumed that

18:20 these were that maybe it was named after the knights who say knee. We thought that would be fun anyway.

18:26 Yeah, yeah, definitely. But Harry J. tells me that this is not true. It's named after a Sanskrit grammarian

18:34 with a P-A. I don't know how to pronounce that either. It's P-A-N-I-N-I. Anyway, thanks. I like fact checking.

18:40 Yeah, it's great to have fact checkers. Awesome. I'm still going to call it Pianini.

18:44 Knee, knee, knee. Yeah, definitely.

18:48 Just know it has a different origin. Okay. Well, thank you, Brian. Thank you everyone for listening.

18:54 Thank you, Rural Bar for sponsoring the show. We will see you all in January. Until then,

18:58 you know, enjoy the winter wonderland. Unless you're down in Australia, then have a nice summer.

19:03 Yeah, definitely. See you next year. Yeah. See you next year. Bye everyone. Bye.

19:06 Thank you for listening to Python Bytes. Follow the show on Twitter via @pythonbytes. That's

19:12 Python Bytes as in B-Y-T-E-S. And get the full show notes at pythonbytes.fm. If you have a news item

19:19 you want featured, just visit pythonbytes.fm and send it our way. We're always on the lookout for

19:24 sharing something cool. On behalf of myself and Brian Okken, this is Michael Kennedy.

19:29 Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page