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:04 It's episode 6, recorded Monday, December 12th.

00:07 This episode is brought to you by Rollbar.

00:09 They help take the pain out of errors.

00:11 Thank you so much Rollbar for sponsoring the show.

00:13 And this is Michael Kennedy, one of your hosts.

00:15 I'm here with Brian Okken, my co-host.

00:17 Hello, Brian. How's it going, man?

00:19 Hello. It's going really good.

00:20 Good, good. This year has gone by quickly, hasn't it?

00:24 It's gone super fast.

00:26 Yeah, I feel like everyone was fixated on the 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.

00:35 How about you?

00:36 I'm going to start writing.

00:39 So yeah, you got a book to finish, man.

00:41 Anyway.

00:42 So the point is, this is actually our last episode of the year.

00:45 So I want to say thanks to everybody who subscribed and listened and shared this, this podcast with their friends.

00:51 We're taking a break and we will be back first thing in January.

00:56 First week.

00:56 We'll have even more news to share, won't we?

00:58 Yeah.

00:59 that'll be like three weeks of stuff to catch up on.

01:02 Yeah, hopefully no drama.

01:04 Okay, so what's the first item you want to share with everyone?

01:07 What did you find?

01:08 Well, there's an article by Dan Bader, "Make your Python code more readable with custom exception classes." This is great.

01:15 He wrote up a little tutorial along with a five-minute video where he walks through stuff.

01:21 He talks about including your own exception classes can make your errors more readable within your code and also communicate to the users of your functions or whatever your intent and what the errors are and also you can add more context. I like it because it's one of those things that I was afraid to add custom exceptions and it's really just pretty darn easy. The main points I think is to remember to derive from either exception or one of the other built-in Python exceptions. Like value error or something like that right? Yeah whatever sort of makes sense and and it's a good one. I also wanted to add that if you are, there's extra things you should do if you're releasing a package and or even within your company. I think it's good to derive from your own, create a custom exception and then derive all your other exceptions from that one. And I got that tip from another article that we'll link to in the show notes by Julian D'Anju.

02:17 Yeah, yeah, yeah. That's a really great point actually because it would be great to do try accept all the errors from this package like whatever is happening in here I want to start by handling those and maybe get more specific ones maybe not but yeah I hadn't really thought about that the make your own special base exception even the reverse try to do specific first and then and then do a catch all of those and then that if it isn't one of your package ones then you can also still catch the general exception and do something different there. Yeah, that's cool. There's two, there's a couple things about this article I like. One, Dan Bader's doing a bunch of cool videos on YouTube. He really seems to be putting a lot of effort to frequently get those out. And so here's an article that takes like five minutes to read, but there's also a five-minute video screencast to go along with it. So well done on that, Dan. And then more generally, this idea here makes it easier for one of my favorite programming patterns, which is also quite Pythonic, is in that it's, the pattern is it's easier to ask for forgiveness than permission. As opposed to like the C++ style look before you leap programming model where you test the heck out of everything and then you try a thing you just here you just do it if it throws an exception you know you catch it and then accept block and it's all good. Yeah definitely like a high level like for instance if I were as an example if I were using requests I could have a special handler that dealt with exceptions from requests and know that that I because I understand what part of systems dealing with that, I could handle it in one place.

03:51 Right, absolutely.

03:52 Yeah.

03:53 Could not contact server, the web server seems to be down something like this, right?

03:57 Beautiful.

03:58 Wouldn't it be awesome if artificial intelligence could just sit there and just help you code?

04:03 I mean, we all know of AI for Siri and silly things like that, but I feel like actually 2016 is a little bit where the future kind of intersected with now.

04:15 The future came to us.

04:16 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.

04:24 But what I want is an AI to help me as a developer.

04:26 How about you?

04:27 Sounds great.

04:28 Yeah, that'd be super cool.

04:29 So, so I actually ran across this thing.

04:32 One of the listeners, Gilberto Diaz, was nice enough to send me a link and an email say, hey, there's this thing that is so cool, you must check it out.

04:39 It's not technically built in Python, but it really supports Python developers in a crazy good way.

04:45 There's this thing called Kite at kite.com, and it's in private beta.

04:49 We were lucky enough to get some early access to it.

04:51 And what it is, is 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.

04:59 If you have two screens, then stick it on the other one.

05:01 And it watches what you do in all sorts of different programming environments, in Sublime Text, in Visual Studio Code, in PyCharm, even Vim or Emacs, there's many, many plugins.

05:13 as you type, it helps you.

05:16 All right, so if you're writing Python code and you type import space, it'll show you the list of the most popular packages.

05:23 If you type R, it'll show you the list of the most popular packages that start with R, like request right at the top.

05:29 Yeah, and then once you import a thing, it'll start showing you documentation about it.

05:33 Here's some examples on how to use that thing you just imported.

05:36 As you start to like, you know, interact with it, like request dot, it'll say, well, the most commonly called function here is get.

05:41 You want to see some examples how to use request.get or like the documentation.

05:45 And it just, it just really is quite cool how much it knows.

05:50 And you know, it does auto completion.

05:52 Like many editors do, it'll it'll like show you on the left, like, here's the things you can complete.

05:57 But what I like about it is it uses like crowdsourcing for popularity.

06:02 So there's like, you know, 10,000 developers working on this.

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

06:11 just alphabetical or something. So I think it's cool. There's a great video you have to watch if you go check this out at kite.com. It's like right there on the homepage.

06:18 I'm looking forward to playing with it. Yeah, you'd mentioned it seems like AI pair programming and does sure sound like that.

06:27 It's quite interesting. I feel like it's more like an artificial intelligence mentor rather than paired programmer. Like it's going, "Oh, by the way, did you know that you actually can call this function? Oh, that package is really cool because it has this thing you might not know about it's kind of like the wiser version rather than like you know pair programming but I think it's great.

06:45 I'm definitely looking forward to trying that. Yeah for sure. I hate it when my data gets messy. Yeah definitely. So there's an article by I'm gonna even try this Jean-Nicolas Hold I think, "Tidy Data in Python". This article is pretty interesting it caught my attention because I often have data that's in a format that I can't use right away and I need to transform it into something else.

07:10 And I didn't ever think of it like changing tables around and completely changing things automatically. Anyway this article gives some some attributes of what problems to look at in datasets. He based it on a paper named "Tidy Data" by Hadley Wickham. He takes the idea of the paper and then transfers it to into Python and how to utilize it in Python with the pandas library.

07:36 And like so this seems very abstract right now but he has some examples of data that's that's really data is in the column headers. He has some attributes to look for like each variable forms a column and contains a value and each observation forms a row and the type of observation units form a table. And it still sounds kind of complex or kind of abstract but the examples really are pretty easy to follow and it's just a neat idea of taking a look at your data and making it more useful. I had never really thought about data in this sense but it seems to me like this talks about how you put your data together so that you'll be it's most natural to take advantage of it with things like pandas and the various data science tools and all sorts of languages but he's focused on Python which is extra cool.

08:31 And so he's had several examples on on you know do things this way not that way and your life will be much easier and I just never thought of systemizing that I guess.

08:40 Yeah, I also I'm looking at the different comparison of before and after tables.

08:45 You can definitely see how it's definitely the the converted table is easier programmatically, but the FROM table, the dirty one, is more broken up like how people look at stuff.

08:59 I didn't think there would be a difference, but it does appear to be it's easier to visualize smaller tables as people, but as computers we need things a little bit more broken down.

09:10 Yeah, it's cool.

09:11 So if you've got a lot of data, especially in tabular form, check that out.

09:15 We're going on break.

09:16 I'm actually heading out on vacation somewhere away from home and I'm still taking my laptop with me because that would be kind of insane.

09:23 But our sponsor, Rollbar, they were going to let me just chill out and not worry about whether the web app is working and not check it all the time.

09:31 I might not use my computer for a few days unless I get notifications on my phone or text messages or Slack or something like that saying, "Hey, your website's down.

09:40 There's this problem." Things are going to be good.

09:42 I'm not going to worry about it.

09:43 That's because I got Rollbar integrated with all the Talk Python stuff, which is really cool.

09:48 If there's a problem, I can just read what the error is and probably fix it pretty easily.

09:52 All the Python Byte listeners, they can have the same peace of mind.

09:54 They just have to go to rollbar.com/pythonbytes and sign up for the free tier.

09:58 Sounds cool, huh?

09:59 Sounds very good.

10:00 Yeah.

10:01 It's good to be on vacation and not worry about things working.

10:04 Just set up the error notifications and you're all good.

10:08 I'm really excited that there's a new version of Python.

10:12 I think people are starting to move 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 We actually have as our next item a video, a conference presentation at PyCon Canada 2016 by Brett Cannon.

10:26 He did a talk called "What's New in Python 3?" 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, they're doing little tweaks here.

10:36 I guess it has new string formatting, whatever." It turns out there are over 16 peps in Python 3.6.

10:42 And that's more than any peps that have been in Python 3, other than the actual creation of Python 3.0 itself.

10:49 That's pretty cool, right?

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

10:56 Yeah, it's gonna be great.

10:57 It's gonna be great.

10:58 The reason I like this video and I want to point it out is we could all go to, you know, what's new in Python 3, and we can read the list like, okay, well, here dictionaries will be ordered.

11:08 now a private identifier or a conversioning number on dictionaries like, "Okay, whatever, who cares?" This gives you the story behind all the changes coming to Python 3.6.

11:18 Why did the core developers of which Brett is one think that this is a good idea?

11:23 How does it help?

11:25 What problem are they really trying to solve deep down when they made this change?

11:30 It really is a cool look inside what's coming with Python 3.6.

11:34 That sounds great.

11:35 I think it's good.

11:37 Python 3.6 release candidate is available right now if you want to download it, but you know if you can wait like five days you should have the final version of Python 3.6.

11:45 They did something with virtual environments, right?

11:47 Yeah, this is one of the things I stumbled across.

11:51 I think it was in a Reddit line somewhere.

11:53 The command line command of pyvenv, which I can't remember which version that came in on one of the 3.0s, that's being deprecated.

12:03 the reason and they want people to use the -mvenv instead and that's so that you specifically tell the virtual environment system which python to use and it makes the programmer know need to know how to get to python first before they create a virtual environment. I think that it totally makes sense it's just something to point out. I think it's important it i'm going to have to actually edit my book because of this because I think I recommended PyV and V in mine.

12:35 Time to un-recommend it.

12:36 Yeah.

12:37 That's cool.

12:38 No, I do think it is good.

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

12:43 And then you can say Python 3 --V and V and then that's the thing you're going to get, right?

12:48 So it is a little more clear, I guess.

12:49 Very cool.

12:50 Yeah.

12:51 It wouldn't be a week in Python without some form of testing or code coverage, right?

12:54 Yeah, definitely.

12:55 And Ned Batchelder, who we all owe some gratitude for, for coming up with, or for taking over the coverage package.

13:03 He's, I interviewed him about that on episode 12 of Testing Code.

13:08 But he's planning a new feature for coverage.py, which will tell us which, so when you run a coverage report, also what functions caused this, or how did you get this stuff covered.

13:22 He covers it in an article. He taught he titled who tests what this is a discussion about kind of how I like the discussion Because those those people new to coverage can kind of peek inside and see you the different stages of how coverage works It goes through measurement and storing the data and then combining the data and reporting because you can't have multiple tests most multiple runs and combine them into it to one report this idea of Trying to figure out which code was covered by which tests is how it started but he comes up with some some reasons why there may be more more uses than just in testing and It's it's a good discussion But part of one of the things he why he wrote this article is is to try to get some help He wants some feedback so some of the questions are He discusses the memory memory usage and in the data model and he wants to know if there's something we need more sophisticated problem solving on this or should we be more conservative with memory and then the output the output right now is Intended to be in JSON, but he wants to know if somebody could use a different data format. I like the direction He's going with it And I think I'll use it and I encourage Anybody that has sort of a non-standard usage of coverage to take a look at this article and give Ned some feedback Yeah, I really like it as well because a lot of times unless you're actually a contributor to the project already feel like the fate of the thing is already determined but this was much more like look we have this challenging problem these are the ways and the trade-offs we're thinking about the ways we're thinking about solving the trade-offs we're contemplating we're not sure where to go if you want to help here's how to help if you want to give us feedback before we jump in and go the wrong direction do it so this is a really cool article just on philosophy as well yeah I think it's great and being able to know which tests actually triggered the covered line when you run a thousand tests well, what's these three? Like, that's pretty interesting.

15:19 Yeah, and you know, before I talked to him, I didn't realize that there was, there were so many features of coverage that I didn't realize, like, being able to have multiple test runs and combine that data and HTML output and things like that.

15:30 It's pretty cool. Yeah, yeah, quite cool, quite cool. So what do you got for us, Michael?

15:34 Alright, I've got one, one final glorious topic for the rest of the year to round out 2016. So here it is, threaded asynchronous magic and how to wield it.

15:45 So this is a really cool article by Christian Medina.

15:49 You know, we had talked about the, I don't remember exactly the title, but that async.io tutorial that was like the G event tutorial remade for async.io and Python 3.4.

15:59 And we're like, "Oh, wouldn't it be cool if there's a great one on async and await?" Like the really, the truly new cool features of Python for threading and parallelism.

16:08 Well, Christian Medina wrote it.

16:11 He wrote a really nice one and it has a bunch of bite-sized examples.

16:15 You can, you know, 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 like, you know, but you realize there's no awaitable asynchronous like way to send mail in Python.

16:31 So well, we're just going to block, but at least we can use this async IO loop for that.

16:36 That's cool.

16:37 talked about the AIO HTTP library, which is an HTTP client server for async IO, and how to do a bunch of parallel web requests. So we often think about requests being the primary way that we do programming against web services and generally HTTP, but this is another option that's really simple that fits exactly into the async IO so you can easily block on the network calls which will then free up the thread to go do other stuff because it knows it's waiting on the network. That sounds cool. Yeah, it's really cool. It covers things like tasks, scheduling tasks, scatter/gather styles of programming, and then even moving the async I/O loop to a background thread so you don't block up your main thread, but you kind of have a place to put all the asynchronous work and let it run on that other one thread, which is pretty cool. So yeah, so thanks Christian for doing that. Got to meet him at PyCon last year and so that was fun and hopefully everyone else is going to PyCon. If you don't have your tickets yet. You need to be getting it, right, Brian?

17:36 Definitely. I missed out last year.

17:38 So don't be sad.

17:40 Get tickets before they sell out because this I'm sure it will sell out.

17:43 It sold out early last year.

17:44 And plus it's in Portland and Portland rocks.

17:47 Portland definitely rocks.

17:48 It's going to be weird.

17:49 They're going to be keeping it weird.

17:50 All right.

17:52 Well, that's it for me.

17:54 I don't really have a whole lot of news to share other than just saying thanks to everyone for listening, you know, for our new podcast.

18:00 It's been fun to do for you and I appreciate all the feedback.

18:03 I appreciate it too.

18:04 Speaking of feedback, we did get one person. I think it's Harry J I hope I didn't pronounce that wrong on Twitter said that he listened to episode 3 and I had mentioned that a library called Pionini that don't know if I'm pronouncing that right, but I Assumed that these were that maybe it was named after the Knights who say knee we thought that would be fun. Anyway, yeah Yeah, definitely but Harry J Tells me that this is not true. It's named after a Sanskrit grammarian with a PA. I don't know how to pronounce that either It's PA and I and I anyway, thanks. I like fact-checking. That's great to have fact checkers. I'll see. I'm still gonna call it piney knee knee knee Just know it has a different origin. Okay. Well, thank you Brian. Thank you everyone for listening Thank you roll bar for sponsoring the show. We will see you all in January until then, 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.

19:05 Yeah, see you next year. Bye everyone.

19:06 Bye.

19:06 Bye.

Back to show page