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


« Return to show page

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

Recorded on Monday, Dec 12, 2016.

00:00 Bytes Transcript

00:00 #6: Python 3.6 is going to be Awesome, Kite: Your Friendly Co-Developing AI

00:00 KENNEDY: This is Python Bytes. Python headlines and news delivered directly to your earbuds. It’s Episode 6, recorded Monday, December 12th.

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

00:00 is Michael Kennedy, one of your hosts. I’m here with Brian Okken, my co-host. Hello, Brian. How’s it going, man?

00:00 OKKEN: Hello. It’s going really good.

00:00 This year has gone by quickly, hasn’t it?

00:00 It’s gone super-fast.

00:00 Yeah. I feel like everyone was fixated on the election because it was so unique then nobody knows what to do with the rest of the year. I’m going to go on vacation, how about you?

00:00 I’m going to start writing.

00:00 Yeah, you gotta book to finish, man.

00:00 the point is, this is actually our last episode of the year. I want to say thanks to everybody who subscribed and listened and shared this podcast with their friends. We’re taking a break and we will be back first thing in January, first week. We’ll have even more news to share, won’t we?

00:00 Yeah, we’ll have three weeks of stuff to catch up on.

00:00 Yeah, hopefully no drama.

00:00 what’s the first item you want to share with everyone? What did you find?

00:00 Well, there’s an article by Dan Bader. “Make Your Python Code More Readable with Custom Exception Classes.” This is great. He wrote up a little tutorial along with a 5-minute video where he walks through stuff. 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. 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 point I think is to remember to derive from either exception or one of the other built-in Python exceptions.

00:00 Like value error, or something like that?

00:00 Yeah, whatever sort of makes sense. It’s a good one. I also wanted to add that there’s extra things you should do if you’re releasing a package 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. I got that tip from another article that we’ll link to in the show notes, by Julien Danjou.

00:00 Yeah, that’s a really great point actually. It would be great to do try except all of the errors from this package. Like, whatever is happening here I want to start by handling those and maybe get more specific ones, maybe not. But I hadn’t really thought about that; the-make-your-own-special-base exception.

00:00 Even the reverse try to do specific first then do a catch all. Then if it isn’t one of your package ones then you can also still catch the general exception and do something different there.

00:00 Yeah, that’s cool. There’s a couple things about this article that 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. So, here’s an article that takes 5 minutes to read. There’s also a 5-minute video screencast to go along with it, so well done on that, Dan.

00:00 more generally, this idea her makes it easier for one of my favorite programming patterns, which is also quite Pythonic in that the pattern is it’s ‘Easier to Ask for Forgiveness than Permission.’ As opposed to the C++ style ‘Before You Leap’ programming model where you test the heck out of everything and you try a thing. Here you just do it. If there’s an exception, you catch it then except lock and it’s all good.

00:00 Yeah, definitely at a high level. For instance, if I were using requests, I could have a special handler that dealt with exceptions from Request. I know that I understand what part of my system is dealing with that, I can handle it on one place.

00:00 Right, absolutely. ‘Could not contact server, the web server seems to be down.’ Something like this, right? Beautiful.

00:00 it be awesome if artificial intelligence could just sit there and help you code? We all know AI for Siri and silly things like that but I feel like 2016 is a little bit where the future intersected with now. The future came to us. There are so many things with AI that are really awesome. There were several AIs that actually on their own invented encryption. But what I want is an AI to help me as a developer. How about you?

00:00 That sounds great.

00:00 That’d be super cool.

00:00 actually ran across this thing. One of the listeners, Gilberto Diaz, was nice enough to send me a link and email saying, ‘There’s this thing that is so cool, you must check it out.’ It’s not technically built in Python but it really supports Python developers in a crazy good way.

00:00 this thing called Kite at kite.com. It’s in private beta. We were lucky enough to get some early access to it. What it is is you install it in your OS and it sits in a sidebar and take up a fifth of your screen, if you have two screens than you stick it on the other one. It watches what you do in all sorts of different program and environments, in Sublime Text, Visual Studio Code, PyCharm, even or Vim or Emacs have many plug ins. As you type, it helps you. If you’re writing Python code and you type Import [space] it will show you a list of the most popular packages. If you type R, it will show you a list of the most popular packages that start with R, with Request right at the top. Once you import a thing, it will start showing you documentation about it. ‘Here’s some examples to use that thing you just imported.’ As you start to interact with it, like Request. [dot], it will say, ‘The most commonly called function in here is called git. Do you want to see some examples on how to use Request.git or the documentation?’ It’s just really quite cool how much it knows. It does autocompletion, like many editors do. It will show you on the left, ‘Here’s the things you can complete.’

00:00 what I like about it is, it uses crowdsourcing for popularity. So, there’s like 10,000 developers working at this, it will say, ‘This is the most popular completion in this situation here.’ Not just alphabetical. 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 right there on the homepage.

00:00 I’m looking forward to playing with it. You mentioned it seems like AI paired-programming. It does sure sound like that.

00:00 I feel like it’s more like an Artificial Intelligence mentor, rather than paired programmer. Instead of 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 that you might not know about…’ It’s kind of like the wiser version, rather than paired programmer. But I think it’s great.

00:00 I’m definitely looking forward to trying that.

00:00 For sure. I hate it when my data gets messy.

00:00 Definitely. There’s an article by Jean-Nicholas Hould, “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. I didn’t every think of it like, changing tables around and completely changing things automatically. This article gives some attributes of what problems to look at and what data sets. He based it on a paper named “Tidy Data” by Hadley Wickham. He takes the idea of the paper then transfers it into Python and how to utilize it in Python with the Pandas library. This seems very abstract right now. He has some examples of data that’s really data in the column ‘headers.’ He has some attributes to look for, like each variable forms a column and contains a value. Each observation forms a row. The type of observation units form a table.

00:00 still sounds kind of abstract but the examples are pretty easy to follow. It’s just a neat idea of taking a look at your data and making it more useful.

00:00 I’d never really thought about data in this sense. It seems to me like this talks about how you put your data together so that it will be its 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.

00:00 has several examples on, ‘Do things this way, not that way, and your life will be much easier.’ I just never thought of systemizing that, I guess.

00:00 Yeah, also looking at the different comparison of before and after tables, you can definitely see how the converted table is easier grammatically, but the ‘from’ table – the dirty one – is more broken up like how people look at stuff. I didn’t think there would be a difference, but it does appear to be easier to visualize smaller tables as people. As computers, we need things a little bit more broken down.

00:00 That’s cool. So, if you’ve got a lot of data, especially in tabular form, check that out.

00:00 going on break. 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.

00:00 sponsor Rollbar, they were going to let me just chill out and not worry whether the web app is working and not check it all the time. 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. There’s this problem.’ Things are going to be good, I’m not going to worry about it because I’ve got Rollbar integrated with all the Talk Python stuff which is really cool. If there’s a problem I can just read what the error is and fix it easily.

00:00 the Python Byte listeners, they can have same peace of mind. They just have to go to Roolbar.com/pythonbytes and sign up for the free tier. Sounds cool, huh?

00:00 Sounds very good.

00:00 It’s good to be on vacation and not worry about things working. Just set up the error notification and you’re all good.

00:00 really excited that there’s a new version of Python. I think people are starting to move on from Legacy Python and at the end of this week there’s going to be one more reason to do so.

00:00 actually have, as our next item, a video of a conference presentation from PyCon Canada 2016 by Brett Cannon. He did a talk called “What’s New in Python 3” and I think it’s interesting. If you look at all the PEPs (Python Enhancement Proposals) and all the stuff that’s coming, they’re doing little tweaks here, sting formatting and whatever. It turns out there are over 16 PEPs in Python 3.6, and that’s more than any PEPs that have been in Python 3, other than the actual creation of Python 3.0 itself. It’s pretty cool, right?

00:00 Maybe we should have had another roll before now. I’m excited for all these.

00:00 This is going to be great. The reason I like this video and I want to point it out is, we could all go to “What’s New in Python 3” and read the list. Dictionaries are ordered, there’s now a private identifier or a versioning number on dictionaries, okay whatever. This gives you the story behind all the changes coming to Python 3.6. Why did the core developers – which Brett is one – think that this is a good idea? How does it help? What problem were they really trying to solve, deep down, when they made this change? It really is a cool look inside what’s coming with Python 3.6.

00:00 That sounds great.

00:00 I think it’s good. So, Python 3.6 release candidate’s available right now is you want to download it. If you can wait 5 days, you should have the final version of Python 3.6.

00:00 did something with virtual environments, right?

00:00 Yeah. It’s one of the things I stumbled across, I think it was in a Reddit line somewhere. The command line command of Pyvenv. I can’t remember which version that came in on, one of the 3.0s; that’s being deprecated. The reason is they want people to use the -m venv instead, and that’s so that you specifically tell the virtual environment system which Python to use. It makes the programmer need to know how to get to Python first before the created virtual environment. It totally makes sense. It’s just something to point out. I think it’s important. I’m going to have to edit my book because of this I think I recommended Pyvenv in mine.

00:00 Time to unrecommend it. (Laughing) That’s cool. I do think that it’s good. You can say Python 3 - - [dash dash] version, see what that is. Then you can say Python 3 -m venv, and that’s the thing you’re going to get. It’s a little more clear, I guess. Very cool.

00:00 wouldn’t be a week in Python without some form of testing or code coverage, right?

00:00 Yeah, definitely. Ned Batchelder, who we all owe some gratitude for taking over the coverage package. I interviewed him about that on Episode #12 of Testing Code. But he’s planning a new feature for coverage.py. Which will tell us when you run a coverage report, what functions cause this, or how did you get this stuff covered. He covers in an article titled “Who Tests What.”

00:00 like the discussion because those people new to coverage can kind of peak inside and see the different stages of how coverage works. It goes through measurement and storing the data and combining the data and reporting, because you can’t have multiple tests, multiple runs, and combine them into 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 reasons why there may be more uses than just in testing.

00:00 a good discussion. Part of one of things why he wrote this article is to try to get some help. He wants some feedback. He discusses memory usage and the data model and he wants to know if we need more sophisticated problem solving on this or should we be more conservative with memory. The output right now is intended to be in JSON but he wants to know if somebody can use a different data format. I like the direction he’s going with it and I think I’ll use it. I encourage anybody that has a non-standard usage of coverage to take a look at this article and give Ned some feedback.

00:00 Yeah, I really like it as well because a lot of times, unless you’re actually a contributor to the project, you feel like the fate of the thing is already determined. But this was much more like, ‘We have this challenging problem. These are the ways we’re thinking about solving it and the trade-offs we’re contemplating. We’re not sure where you want 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.’ This is a really cool article on philosophy as well.

00:00 Yeah. I think it’s great.

00:00 And being able to know which test actually triggered the covered line, when you run a thousand tests. Well, these three. That’s pretty interesting.

00:00 Yeah. Before I talked to him I didn’t realize there were so many features of coverages, like being able to have multiple test runs and combine that data. And HTML output and things like that.

00:00 Yeah, quite cool.

00:00 So, what’ve you got for us Michael?

00:00 I’ve got one final glorious topic for the rest of the year, to round out 2016. Here it is: “Threaded Asynchronous Magic and How to Wield It.” This is a really cool article by Cristian Medina.

00:00 had talked about – I don’t remember exactly the title – but that Asyncio tutorial that was like the G event tutorial remade for Asyncio in Python 3.4. We were like, ‘Wouldn’t it be cool if there was a great one on Asyncio 08 like the truly new cool features on Python for threading and parallels?’ Well, Cristian Medina wrote it. He wrote a really nice one and it has a bunch of bite-sized examples. They’re not too large but they don’t seem entirely fake. He has one example of sending an email notifications, sort of asynchronously. But you realize there’s no asynchronous way to send mail in Python. Well, we’re just going to block. But at least we can use the Asyncio loop for that, that’s cool.

00:00 it also talked about the AIO HTTP library, which is an HTTP client server for Asyncio and how to do a bunch of parallel web requests. We often think about requests being the primary way that we do programming against web services and general HTTP, but this is another option that’s really simple. It fits exactly into the Asyncio so you can easily block on the network calls which will then free up the thread to go to other stuff because it knows it’s waiting on the network.

00:00 That sounds cool.

00:00 Yeah, it’s really cool. It covers things like tasks, scheduling tasks, scatter gather dials of programming; even moving the Asyncio loop to a background thread so you don’t block up your main thread but have a place to put all the asynchronous work and let it run on that other one thread. Which pretty cool.

00:00 Cristian for doing that. Got to meet him at PyCon last year; that was fun. Hopefully everyone else is going to PyCon. If you don’t have your tickets yet, you need to be getting it. Right, Brian?

00:00 Definitely. I missed out last year.

00:00 Don’t be sad. Get tickets before they sell out. I’m sure it will sell out. It sold out early last year.

00:00 Plus, it’s in Portland. Portland rocks.

00:00 Portland definitely rocks. It’s gonna be weird. They’re going to be keeping it weird.

00:00 that’s it for me. I don’t really have a whole lot of news to share, other than saying thanks everyone for listening to out new podcast. It’s been fun to do for you and I appreciate all the feedback.

00:00 I appreciate it, too. Speaking of feedback, we did get one person. I think it’s Harry J. on Twitter. He said he listened to Episode #3 and I had mentioned that a library called pynini, I assumed was maybe name after the “Knights Who Say Nee.”

00:00 We thought that would be fun anyway.

00:00 But Harry J. tells me that this is not true. It’s named a Sanskrit grammarian with a Pāṇini. Thanks, I like fact-checking.

00:00 It’s great to have fact-checking. Awesome. I’m still going to call it Py-Nee Nee. (Laughing) Just know it has a different origin.

00:00 thank you, Brian. Thank you, everyone for listening. Thank you, Rollbar for sponsoring the show. We will see you all in January. Until then, enjoy the winter wonderland. Unless you’re down in Australia, then have a nice summer.

00:00 See you next year.

00:00 See you next year, everyone.

00:00 you for listening to Python Bytes. Follow the show on Twitter via @pythonbytes and get the full show notes at pythonbytes.fm. If you have a news item you want featured, just visit pythonbyes.fm and send it our way. We’re always on the lookout for sharing something cool. On behalf of myself and Brian Okken, this is Michael Kennedy. Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page