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

Transcript #190: You will now be notified if the Python zipper is broken

Return to episode page view on github
Recorded on Wednesday, Jul 8, 2020.

00:00 Hello and welcome to Python Bytes where we deliver Python news and headlines directly to your earbuds.

00:05 This is episode 190 recorded July 8, 2020. At least it's the 8th here. I'm not sure what it is in Australia. Is it tomorrow already?

00:14 It's the 9th.

00:15 Oh my god, you're from the future. Anthony Shaw is here and he is from the future.

00:19 That's awesome.

00:20 I'm Michael, as everyone knows. And Anthony, thank you for joining the two of us here on the show. Happy to have you.

00:26 Yeah, I'm glad to be here.

00:27 I want to kick this off with a, I think an interesting article.

00:30 It's a, by Tom Christie titled Python async frameworks beyond developer tribalism.

00:36 And I think it's a, and Tom Christie, if you don't know who he is, he's done some things like the Django rest framework and HTTPX, of course, other people are on those projects as well, but right guy, and I think it's in part to a reaction, we didn't cover this article, but we noticed it prior article called "Async Python is not faster." But all of us had some issues with the article itself.

01:01 And so this isn't a direct rebuttal, but it's an interesting read.

01:05 One of the things Tom Christie's pointing out is just that I think that we need to move the Python community beyond polarizing discussions.

01:14 And I think that "Async Python is not faster" was not a helpful discussion, but it's part of it anyway.

01:22 A little bit of a quote, we could probably benefit from a bit more recognition of where there is shared ground and in the areas where there's less clarity, have constructive conversations around those.

01:33 And so some of the shared ground Tom points out is kind of one of the things is you really shouldn't really care about performance too much when you start a project.

01:43 The success of a project is more related to developer experience and the strengths surrounding the ecosystem of the framework you're using, not just whether or not it's faster.

01:53 And you should care, but we as the Python community do need to care about web performance, partly because new projects starting off might decide to go with non-Python solution because they fear Python might be too slow.

02:07 - And Anthony, how often have either of you heard, oh, we decided to rewrite that in Go, so we have proper async, or we decided to use JavaScript here because it supports async through Node or something like that.

02:19 Like I've heard that a lot.

02:20 - Yeah, definitely. Lots of projects.

02:22 - Yeah. And I'm not sure, I don't know anything about those other languages though.

02:26 So at least I haven't used them, but for me, it would be a mistake because I know Python.

02:32 I don't know those other ones.

02:34 Okay. So that's one of the points that maybe we should care a little bit, but also we should be careful about the word performance because if you measure performance of just a single async function calls with our single function call, An async call is going to be slightly slower because there's a little bit of async overhead.

02:55 But we don't use async because we want single threaded applications to be faster.

03:00 We use it because especially IO bound concurrent tasks are, they scale better with async.

03:08 The other aspect we wanted to talk about was there's just really, you have to be careful with looking at benchmark data because benchmarks are often geared to select it to tell the story that the person writing the article wants to convey. Or the situation that they're trying to solve, right?

03:26 They're like, oh, I thought this would help. I tried to solve with this.

03:28 Turns out it doesn't. It must be bad.

03:30 Yeah. Right. Okay. So there's some things that they're just reasonable statements.

03:34 And there are some valid differences, like for instance, should web frameworks, the web frameworks we have now, should they start converting to async or should we just leave them as they are and develop new frameworks that are async native. Those are some differences.

03:53 There's also different approaches which is part of the confusion and part of the discussion is there's async io, there's also trio and twisted and curio, and you know how to decide which one.

04:04 There is some confusion there and I think that's valid. So the discourse and the discussion is important, but I think it's important Tom points out to say basically we need to keep it the benefits of of adopting genuine collaborative mindset are good rather than a competitive mindset.

04:19 So let's not fight with each other.

04:21 There may be different or everybody's working on different little corners of the landscape, but we're still trying to appreciate, move the move async and move web forward for Python.

04:33 So stay positive, be happy.

04:35 - Be happy man.

04:37 Well, I didn't want to just call this other article out and criticize it.

04:41 'Cause I don't think that adds a lot of value.

04:43 I don't think we want to cover items just to criticize them, except for their rare moments where it's getting a ton of attention.

04:50 And if you think there's an inaccuracy, you probably should call it.

04:52 I'm glad Tom wrote this article. I think Tom wrote it, right?

04:55 I mean, it's not attributed, but it's from basically his organization.

04:59 So I'm pretty sure.

05:00 Yeah, I had to go look at the GitHub repo to see who did the push that commits for this article. So, yep, it was Tom.

05:07 What an interesting way to attribute it. Very cool.

05:10 I honestly believe that other article which you're linking to is inaccurate. I think it's trying to apply async to a situation where it's not very warranted. It's like, this hammer is really bad at unscrewing this nail, or this, unscrewing this screw, hammers are bad, right? Well, hammers aren't for that.

05:27 Async stuff is for scaling when there is a waiting period, when you're, there's a latency when you're waiting on something.

05:33 And the setup there was, the DB was 100% maxed out, So there was no way to like push that waiting and get more out of the database.

05:41 And there was almost no waiting, like a few milliseconds anyway.

05:44 And so the overhead didn't make any sense.

05:47 Somebody wrote me and said, Michael, please, I don't know your thoughts on this.

05:50 So I went ahead and did a little quick test.

05:53 I've got my async course, I've got some stuff where we go and talk to things on the internet, where there's like ping time latency and stuff.

05:59 And it goes and gets 10 items off a web server, ping times like 100 milliseconds or something.

06:05 it was 750% faster to use the async version than not the async version.

06:11 I changed that number to get 100 of them, and it went from 50 seconds, almost one minute down to two and a half seconds.

06:18 1750% faster.

06:21 Async is about scaling the waiting part.

06:24 If there's no waiting, there's no benefit, there's just overhead.

06:27 The one thing I have to, I guess I'm gonna be on the other side a little bit.

06:30 The async is not faster article.

06:32 One of the things you did point out was a lot of the async framework benchmarks and the benchmark numbers are not really that fair because there there's other ways you can speed up the other platforms by, for instance, adding processors or CPUs, adding more cores to different applications, and that maybe the original application was just misconfigured.

06:56 I think that's valid, but it doesn't mean that async is bad.

07:00 - Yeah, I think... - It definitely adds some complexity. Go ahead, Nat.

07:02 If you're comparing it with multi-threading, I think that's the comparison.

07:06 I think if you're just looking at, "I've got single sequential code, does adding async make it faster?" If it's something that's IO-bound, yes, is the answer.

07:14 But if you're comparing it to multi-threading, so using the threading module to spawn threads, then I think that's where you see the performance improvement.

07:22 So I've got some micro-benchmarks doing TCP port scanning across all the different ways you can do concurrency and parallelism in Python.

07:31 And async was the fastest of all those options. And it cuts down a lot of the overhead from threading because the way that threads work in Python, they've kind of got this bootstrap module that kind of has to load some of the stuff that it needs for context.

07:47 And whereas async doesn't need that. So it kind of cuts down a lot of that overhead. I think what are the challenges I've had with async in the earlier versions where it got released was the amount of boilerplate code and kind of like infrastructure you needed to put in just to do something really simple, which is like I want to run this function asynchronously Like I don't care about what how the event loops and all that kind of stuff Like i've used other languages. I want to kick it off and forget it It's like why can't I just call this function and let it go? What is all this stuff i'm doing?

08:18 Yeah, exactly. So I've used other languages where the async is a bit more fluent. I've been using the Kotlin async last week and I've used .NET, C#, the task API, which is really, really nice to use. The other challenge is which bit of code owns the event loop. And that's like an anti-pattern where you end up with a God class that's kind of doing everything. And you've kind of then got to think about how you factor the application so that, okay, which bit owns the event loop?

08:49 How do I construct that? Where does it end? We were helped on the real Python community group. Somebody was asking some questions. They'd async or is it multi-threading into their code?

08:59 And we were just trying to get them to refactor it to take all the logic out of the function that was being multi-threaded and put it into the master and just put the minimal amount of code in the threaded function. I think there's still a whole bunch of stuff like that, which people need some good learning on and they need to get used to.

09:17 It's like a different way of writing code.

09:19 It's not just something that you can sprinkle on top and it suddenly makes your code faster.

09:24 I think that's the, that's part of the misunderstanding.

09:26 Yeah.

09:26 Especially in Python, where it takes that extra step of you got to manage the loop and then you've got to run it.

09:32 And it's not like kind of, I've kicked off a bunch of stuff and now it's all just happening.

09:36 Yeah.

09:36 They made that simpler in 3.7 and 3.8.

09:40 They've kind of got some shortcut modules that...

09:43 So I think it's now like one or two lines of extra code you need as boilerplate just to get up and running.

09:50 So it's a lot better than it was in the earlier versions.

09:52 But even if it's not a lot of extra code, and Tom Christie points this out, multithreading and Async are more complicated than not.

10:01 So that's just a reality.

10:03 Whether or not the code's too much more complicated, the entire design is different.

10:08 And it's a reality that isn't to say, don't do async or don't do multithreading.

10:14 It's just, you don't get it for free.

10:16 I think almost the opposite, in a sense.

10:19 I think the code is not complicated enough.

10:22 On the other hand, like it looks close enough that people don't realize they have to change their mindset and like approach it in an entirely different way.

10:30 And they feel like, oh, I just call it this way now.

10:31 But then they run into these issues.

10:33 They're like, oh, this is broken. Like, why is it not working?

10:35 Or, you know, like, You think you can just do it one way, but you really, if you don't have a little deeper understanding, you can just go down the wrong path also.

10:43 Yeah.

10:43 Alright, well, that was interesting.

10:45 Thanks for bringing that up, and thanks, Tom, for writing that.

10:47 Anthony, I'm glad you're here to have another opinion as well.

10:50 I agree that the C# async and await stuff is like the gold standard.

10:54 It's really, really well done.

10:55 So let's talk about something way simpler.

10:59 You want to be a good citizen of your GitHub projects, right?

11:02 Sure.

11:02 You want to have good commit messages.

11:04 There's a major change, you want to bump the version, all those kinds of things, right?

11:09 So you should use Comitizen.

11:11 Comitizen is a command line interface, basically, that wraps around Git, but it has a menu option for different things, and it guides you through doing them a little bit better.

11:25 So you can say, "CZ," and it'll drop down a list.

11:30 You can pick commit or whatever, and then it'll ask you questions like, "Okay, well, what are you trying to do?

11:35 Are you trying to add a feature?

11:36 Are you trying to do a bug fix?

11:38 Is it a PR?" And it'll ask you a couple of questions and it'll generate interesting things like, "Hey, is this a breaking change?

11:45 Would you like me to increment the major version as part of this?" and so on.

11:50 So it does all sorts of interesting things around kind of structuring your interaction with Git.

11:55 So rules for projects, auto-bumping versions, auto-change log generation, all that kind of stuff.

12:01 And it's really meant for teams So they all interact with Git in a consistent way.

12:05 - This is cool.

12:06 - Yeah, neat, right?

12:07 Yeah, and if you go to it, it has a beautiful animated GIF showing how it works right on the GitHub repo.

12:13 Gotta love that.

12:14 - So do you, I was just curious, do you normally commit through command line or through something else?

12:19 - No, no, I commit either through PyCharm or SourceTree, depending on what I'm doing.

12:23 - Yeah, I do both.

12:24 - Yeah.

12:25 - If I'm in PyCharm in a project, then I'll do it through there.

12:28 If I'm doing something else, So like sometimes it's like little hacks or scripts and stuff like that, then I'll do it on the command line.

12:35 - Like a presentation that's in say PowerPoint or something.

12:38 - Yeah, yeah, I'm committing my PowerPoint presentation in.

12:41 (laughing)

12:43 Then I'd use the command line, but I've got a whole bunch of aliases to do 'cause you should always sign your commits and stuff like that.

12:49 So put some aliases and something else would be really helpful that a lot of people don't know is that you know how if you do git commit on the command line, it uses Vim as the message editor by default.

12:59 actually change that. So if you wanted to use another editor, like Emacs or notepad plus plus or maybe even Microsoft Word, then you can change the configuration. And in the command line, you never have to use them ever again.

13:13 I like that. I think a great prank that people said, I'll do it. Don't maybe not all sneak into your co workers computer if they run away for lunch and don't lock it and set word as the editor.

13:27 So next time you go to do something and there's a merge error, like it pops up word, you're like, "What in the world is going on here?" - But your commit messages are going to be like 10,000 lines of XML.

13:36 (laughing)

13:38 - Exactly, exactly.

13:40 Now that's cool.

13:41 This thing, this commitizen also comes with a get pre-commit hook.

13:45 So you can set it up there as well.

13:47 And you can ask it for things like, you just say, run the bump or generate the change log or validate the schema of a message or whatever. So pretty cool.

13:57 It generates a changelog. I've been looking for something to do that for ages.

14:01 I've got projects in Git and when I make a release, I have to remember what got merged, which PRs got merged, who did them, so you can attribute them.

14:11 I don't know what the output is, but it says you know, CZ space changelog or CH for the shortness is what it will do. And it says generates changelog by overwriting an existing file if it's already there.

14:25 I don't know how it knows how far back to go.

14:28 Maybe from like a major version bump or something like that.

14:32 But anyway, give it a try and give us a report.

14:35 We'll find out if it's actually useful for you.

14:37 All right, well, that's it for commitizen.

14:39 It seems like a cool little shortcut.

14:41 I don't know if I'll use it or not because I don't work in large teams that really need this very much.

14:46 So it's just like one more thing.

14:47 But if I did, it would be cool.

14:49 Next up, I've got around PyCon.

14:52 Weren't we supposed to meet at PyCon in Pittsburgh and share a beer?

14:55 the three of us and like, no, didn't happen.

14:58 It didn't happen.

14:59 It was touch and go as well.

15:00 Like I remember a few weeks before whether or not I was going to happen.

15:05 I mean, I think canceling it was definitely the right decision.

15:07 Oh, and it wasn't really canceled.

15:09 I mean, it was moved online.

15:11 And that's what I wanted to talk about was, you know, with all the pycons happening all around the world, like I've been looking at which ones have made the move to go online.

15:20 I mean, there's I guess there's like pros and cons to this.

15:24 I know some people miss out on meeting people and chatting to people on the hallway track.

15:28 You're never going to replace that with an online conference. And I think, set your expectations low when it comes to interaction with other people. But the one big upside is that I think it makes the talks more accessible. So if I go to a big PyCon, I probably say I watch maybe like 10 talks over the PyCon, and there's probably like 100.

15:53 that I could have watched if I just sat in the talk rooms.

15:56 But like, that's not half the reason I'm there is not to watch the talks.

15:59 Like I watch a lot of them afterwards.

16:01 So I think what's been happening is quite a few PyCons have just canceled altogether.

16:06 PyCon Israel, Odessa in Ukraine, EuroCyPy Brazil, PyCon UK, PyCon Thailand, PyCon Spain, DragonPy, which is Slovenia, PyLatam, PyCon DE, which is Germany, and PyCon CZ, which I assume is the Czech Republic.

16:23 They've all been canceled altogether.

16:26 And then a number of PyCon conferences have said, we're going to go online.

16:29 And the cool thing about these is that anywhere in the world you can go and watch the talks.

16:34 And I think something that's kind of happened as part of this is that some of the big PyCons like US and like Europe, they had like video crews to film the talks and like, you know, write all the subtitles and figure out how all the AV to get the sound nice and stuff like that.

16:54 But other than the really big conferences, the smaller ones couldn't really figure that out.

16:58 So some of them had the talks online, but like the quality was really not watchable.

17:03 But a big change with moving all the talks online is that people are recording at home in lockdown and the quality tends to be a lot better.

17:12 Like you can hear what they're saying and the audio is better.

17:16 And so there's more focus on getting the online experience better.

17:21 And as an added bonus, just as a Python enthusiast, even, or a PyCon enthusiast, you can just sit and watch PyCon talks from all over the world in your slippers, or in your Ugg boots if you're in Australia.

17:35 And it's great, like I, you know, beam it onto the TV using Google Chromecast.

17:41 And you can just sit in your living room and watch like PyCon talks from us watching some from Japan, some from like the some of the US conferences, some of the European conferences, and there's some really good talks that would have made great talks, you know, the bigger conferences that are in the smaller regional ones that are in there. So some of the ones that I found, which are online, like on us, obviously, the Python web conference, Flask on SciPy and PyHEP, which is high energy physics, I think, will be online.

18:14 EuroPython will be online. PyCon Japan, they released a whole bunch of talks this week.

18:20 PyCon AU will be online. And I've submitted a talk for that, fingers crossed. PyCon Bolivia will be online. PyCon ZERE, which is South Africa, will be online. PyCon APAC in Malaysia will be online, Hong Kong, Paibei, which is in the US and California and Paikon Africa will all be online. So there's at least, from what I could find, at least 15 Paikons around the world. So let's say each one has like 50 talks. That's like a lot of talks.

18:49 That is a ton of talks. And you can just drop into some of these places that you might have a really hard time visiting, like, maybe Malaysia is far away, or Africa is far away, but you would love to experience what the community is like there. Yeah, a lot of great stuff.

19:04 There are actually a few PyCons that from what I can tell are happening in person. Around the world, I guess the lockdown situation is very different depending on the country.

19:14 So PyCon Taiwan, PyCon Italia and PyCon Russia from what I can tell are still happening.

19:21 So yeah, I know the situation in Taiwan is much better. Italy, I think is late in the year. So they're probably hoping that that's going to calm down in Russia. I don't know what's going on there. But I picked out a few talks as well that I really liked from some of the regional conferences. Deceptive Security Using Python by Kajendra Deshpande.

19:40 If Statements are a Codesmell by Ali from Chippy. That was the PyCon US talk. Stop Using Mocks by Harry Percival. That's a great talk. This one is in Japanese, and there are no subtitles. But But if you speak Japanese, network analysis and text PEP in analysis, which is like an analysis of all the peps by Tomoko Furuki, using Python to detect vulnerabilities and binaries by Terry Oda.

20:07 That was a good talk and optimize Python and Django with Postgres superpowers by Louise Gagnon, which was a PyCon US talk. So yeah, I've made a little playlist of stuff that I really enjoyed from some of the regional conferences and the links will be in the show notes.

20:24 - Nice. - These are all great.

20:25 Yeah, love it.

20:27 And you talked about the smaller conferences not necessarily having the AV set up, put things online properly.

20:33 Now all these talks that went online, they were made digitally native, right?

20:38 They were made first for this experience, right?

20:40 They weren't like, oh, there's a camera way back there and we'll just zoom in and we'll try to show it, right?

20:45 It was like yours, you had sort of an introduction.

20:47 It was like the video we got here, you taking back and talking, then it would just focus in on the screen and whatnot.

20:55 So a little bit different there.

20:56 - Yeah, definitely.

20:56 And you should definitely watch Brian's talk from PyCon US.

21:00 I did watch your talk, Brian, and you should watch mine as well if you're interested, which is on the Wise Python Sloan.

21:06 Brian's was on parameter, it was on testing, wasn't it, Brian?

21:09 - Parameterized testing.

21:10 - Yeah, parameterized testing.

21:12 - Absolutely.

21:13 - That was a good talk.

21:14 - And I was surprised to hear my name mentioned in Harry's talk, which is, it was cool.

21:18 - Oh yeah.

21:19 (laughing)

21:20 - That's cool.

21:21 - Yeah, very nice.

21:21 And it's a bummer to not go to these conferences, but at the same time, there are a bunch of people who now can experience those presentations who otherwise wouldn't have been able to.

21:31 - Yeah, this is a huge benefit.

21:32 - And I'm really excited to see, like you said, there's conferences that either had bad video or just couldn't afford a great AV crew or didn't.

21:42 And some of the conferences will just do like the entire day video and you have to pick it out and that's more difficult.

21:48 - I'm four hours and 17 minutes into it.

21:50 - Oh, okay.

21:51 - Yeah.

21:52 - That's discoverable.

21:52 - I'm really excited to be able to see all these videos from all over.

21:56 Although I won't be able to, I only speak English.

21:58 So how many languages do you speak, Antony?

22:01 - Oh me, oh, I'm learning Japanese.

22:03 So I was watching the PyCon JP talk and catching every 10th word.

22:09 - Okay.

22:10 - And the slides definitely help.

22:12 And I speak Pidgin French as well.

22:14 - Okay.

22:14 I was impressed that you were watching the Japanese videos.

22:17 - Oh, that's how I discovered as well your Python testing with PyTest book in Japanese.

22:21 It was like part of the, it was on the slide and I was like, it just said lots of stuff on the cover in Japanese and then you saw the word Brian Okken.

22:29 I was like, oh, I know that guy.

22:31 Yeah, I got to try to get somebody that travels to Japan when things open up to pick up a copy for me.

22:38 Yeah, definitely.

22:38 See.

22:38 Yeah, that's cool.

22:39 Also cool, speaking of your book, people want to support the show, they could get your book.

22:43 Yeah, that'd be great.

22:44 I wanted to do something special.

22:46 I was looking at the reviews online on Amazon, but I know there's reviews other places, but this was really kind of cool. I'm going to do an excerpt from Patrick Kennedy's review.

22:55 "This book provides a gentle introduction to what the PyTest framework is, how to use it, and how to develop tests using PyTest. I had never understood what fixtures in PyTest were prior to this book, but now they make complete sense to me. Excellent book, and I highly they recommend it to anyone wanting to learn about PyTest.

23:13 So thanks, Patrick, that's a cool review.

23:16 And I went and looked at the numbers.

23:18 There's thousands of people that have read the book, and I know many of the listeners have, so I would love to hear more reviews.

23:24 So if you have a review somewhere, either on Amazon or Goodreads or somewhere else, let me know where the review is, and I'd love to hear what you think.

23:32 That'd be cool. - Awesome.

23:33 I think the timing for this will still work out, fairly.

23:37 Some of our courses are offered in the Humble Bundle right now.

23:40 So there's a special Python Humble Bundle going on.

23:43 This episode will be out in a week, so it should be wrapping up, but it should still be going if you listened soon enough.

23:48 I think it ends July 22nd.

23:50 So before then, if you want to get a whole bunch of Python goodies, including free courses from Talk Python, go there and check it out.

23:58 And of course, check out all of our courses as well.

24:01 You get a lot for your value, even without the bundle.

24:03 - Yeah, for sure. - It's good.

24:05 Thanks.

24:06 You know what?

24:06 What happens if you try to zip stuff together, as an inner tool zip. And they, they don't match just like the zipper stick at the end. Does it go all the way to the end and then come off? Like is it when you're sleeping bag comes apart in the middle and you're like, I'm gonna be really cold tonight.

24:21 I can't fix this. What happens?

24:22 Whatever doesn't fit just gets cut off. So brutal. Yeah, so I wanted to highlight PEP 618. So I have actually run into this a lot. So in the normal circumstances, so zip's a cool thing if you haven't I'm sure everybody's used it but if you haven't used it before it just takes two two intervals or more more than one it's often two in my case but you can do more than two intervals and then makes a new iterable with pairwise tuples of whatever's in there so if you've got a list with one two three and abc and another list you can zip them up and your your elements of your new list will be 1a, 2b, 3c, that sort of thing.

25:05 So, often they're used where you just kind of know that all the links are supposed to be the same because if they're not the same, it chops them off.

25:13 It does it, you get a list of the shortest, shortest common list.

25:17 And that's surprising and sometimes.

25:21 It might be okay, but it's probably indicative of like bad data.

25:25 And who knows if it's off by the end or off by the beginning, or they shouldn't go together, it's not a good sign.

25:31 When I'm using it and it's a kind of a mission critical sort of thing, I'm definitely checking the links first, and it annoys me that I have to.

25:39 So the change is in PEP618, it's not, you know, it has been accepted for 3.10.

25:45 So it will go into Python 3.10, and the change is really there's a new keyword, so in zip you can add strict equals true, And that will, if the links are not the same, it'll raise a value error.

25:59 So you'll get an exception if the links are not the same.

26:02 So you can just instead of, I think it's a good thing.

26:05 It'll simplify a lot of my code.

26:07 Yeah, Anthony, what do you think?

26:08 I never use zip.

26:09 I only use it in the answer to a Stack Overflow question, where that's the solution and I copy and paste it into my code.

26:16 Normally about like, how do I merge two dictionaries? I think that's like, And it's like, oh, you just do star star list star star zip star star something.

26:24 Okay, I don't understand how that works.

26:28 You're like star star, maybe more explicit.

26:30 So let's just stick it in and see if it works.

26:33 Yeah, I never use zip. So that sounds useful.

26:36 I did stumble across 3.9 has a some new functions on the strings, remove suffix and remove.

26:44 Yes.

26:45 Yeah. So we talked about that last time, which I don't think we've released. So you wouldn't know.

26:49 - Oh.

26:51 - But it's so confusing because string.

26:53 Like if you have the word first, the number one, then st and you said strip st, it's not necessarily taking away the st.

27:00 It will, but it might also take an s or a t off the front as well, right?

27:05 It's take away all the characters that are in this list no matter what, not this exact substring, right?

27:12 And so yeah, that's super valuable.

27:13 I'm really excited to have that because it should have been there before.

27:16 I think they should have come up with a more fun exception than a value error. Like it could derive from value error, but it should be like, you know, the zipper broke exception error or like, come on, opportunity missed. All right, let's stick with the standard library.

27:31 This was really interesting to me. I've had Paul Gensel on talk by thon recently.

27:36 I don't know if you guys have listened to it. So you might not be able to ask you the question with you, you actually knowing, but this always frustrated me when I go to a time delta, I do some math, like subtracting one day time from another, I get it back, I'm like, cool, it has a certain number of seconds.

27:54 It also has days and other things on it as well, but those aren't like total days.

27:59 It's not like 7.2 days, it's like eight days and then some negative seconds or something weird, right, really weird, like negative and positive time.

28:08 So those are more for like internal computation, or as I can tell, they probably should be hidden.

28:13 But anyway, if I want to know, say, how many hours has it been?

28:17 How do I do that?

28:18 I would go dt.totalSeconds.

28:21 Okay, well, there's 60 seconds, so I divide by 60, and I want to know, that's minutes, and I want to know hours, so I divide by 60 again.

28:26 And I never put it together.

28:28 I don't divide by, like, 3,600.

28:29 I divide by 60 and then divide by 60.

28:31 So it's clear I'm trying to take away the, you know, get to minutes and then to hours.

28:36 Is there a better way?

28:38 Right, why is there not a total hours, a total weeks, a total months, whatever, on there.

28:43 Like, why do I have to always do math whenever I want to know simple things, like how many hours have passed?

28:48 - Okay. - Well, okay, so the people who built Daytime, or sorry, Time Delta specifically, they didn't intend you to do math.

28:54 They just didn't make it obvious or very discoverable because time deltas can be divided by time deltas.

29:01 So if I want to know how many hours it has been, I can say, like, take the total time delta and divide it by time delta where hours equals one.

29:08 Or if I want blocks of six hours, that could divide it by hours equals six.

29:11 If I want to know how many weeks, I would take the total time delta and divide it by time delta days equals seven.

29:18 And that'll tell me how many weeks.

29:19 - That's pretty awesome.

29:20 I had no idea that it did that.

29:22 - I had no idea either.

29:23 And I was complaining to Paul Gansel, who works on this stuff, like, dude, give us something more than seconds.

29:28 Why are we only getting seconds?

29:30 I want total hours, I want total days.

29:32 He's like, just divide it.

29:33 Just set the days to be one and divide it.

29:35 I'm like, what?

29:36 You can do that?

29:37 Why didn't anybody tell anybody this?

29:40 Anthony, did you know this?

29:41 No, but this is a podcast, so you probably could see I had my head in my hands for that explanation.

29:45 But Division Operator would be like, the last thing I'd ever try.

29:50 I know. Yeah, me too.

29:52 I really thought I'm just like, this is the official.

29:55 This is really the way. Yeah.

29:56 I mean, yeah, this is the way.

29:58 But after this episode came out, Jeff went to I don't know his last name, but on the comment, he said his name was Jeff.

30:05 So Jeff went to the episode page and said, "Learning you can divide a time delta by a time delta to come up with days, weeks, etc.

30:10 is like the Python tip of the year." It's certainly going to save me a lot of pain going, "Wait, there's two 60s. I divide by 60 twice. Sorry, that was actually hours, not days or whatever, like weird 60th of what I wanted or 60 times as many days as I meant." So, yeah, you can divide a time delta by some arbitrary time delta.

30:34 like days equal five and you'll get how many blocks of five days would have been in there as a number.

30:39 I'm not saying this is how it should be.

30:41 But I'm telling you, this is the way to figure out time ranges in Python standard library without doing math.

30:49 Well, so I looked it up. It isn't obvious that, I mean, it does say that you can do division.

30:55 But there's all sorts of other stuff too. You can do like, you can do floor division, you can do modulo.

31:01 - And... - Modulo? How interesting.

31:04 - I mean, it makes sense, I guess, but wow. - And multiplication and...

31:07 - Modulo by seven days. - Yeah.

31:09 [LAUGHTER]

31:11 Like, crazy. I had no idea all this math was available for time deltas.

31:15 Can you use the matrix multiplication operator?

31:18 [LAUGHTER]

31:19 I wouldn't do that. It'll shoot you into the future.

31:21 Oh, wait. Anthony's already in the future.

31:23 I don't know. It's worth trying.

31:25 - Is it like @* or something? Like, ridiculous? - Yeah, yeah, yeah.

31:28 - Power operator. - Yeah, yeah.

31:30 Anyway, I thought probably if I was as surprised about this and the other listeners were as well and it sounds like you guys also didn't know about this, like we should at least mention apparently this is a thing.

31:40 Total tip of the year.

31:42 Yeah.

31:43 Yeah.

31:44 Well, totally.

31:45 If you want to make a really tricky job interview, please don't do it.

31:47 Yeah.

31:48 I remember my kids recently asked me because we were talking about like weeks and these numbers came up and they were like, why do you know how many seconds are in a week and how many seconds are in a day and stuff like that?

31:59 I'm like, because I've memorized those numbers, because I've been programming in languages that make you memorize how many seconds are in a week.

32:08 Because there's not a total hours, there's only a total seconds and I need to know how many hours this is.

32:12 Exactly.

32:13 Nice.

32:14 So here you go.

32:15 Here you go.

32:16 Pretty cool.

32:17 So Anthony, are you a fan of multi Python?

32:21 Multi Python?

32:22 Yes.

32:23 Yeah.

32:24 So apparently Microsoft is as well.

32:25 Yeah.

32:26 to figure out the connection, but it was in the release notes. So they've released a new extension for VS Code, and I'll explain why. But it's called PyLance, and it's named after Lancelot from Monty Python and the Holy Grail, who was... Sir Lancelot? It was, wasn't it?

32:41 Yeah, he was the first one to get across the bridge with the hard questions.

32:45 So yeah, this is an extension for VS Code. So if you're already using VS Code, you should download this and check it out. It's designed to be used with the existing Python extensions. It's not a replacement for the Python extension for VS Code. And I think something about the Python extension is that if you're doing type checking, you're like type hints and stuff like that, or you're using a linter, if you use the Python extension, you can turn on a linter and and it will use one of the Python linters from the extension by spawning like a process every time you edit the code and running the linter again.

33:24 There's also something called the Python language server, which is written in .NET for some reason.

33:31 And that is then communicated with by the BS code to figure out like the Python code and look at the AST and stuff.

33:39 And that gives some errors and code like highlights when you make mistakes in Python.

33:43 So this Pylance is an extension that basically provides type hints and then it does a whole bunch of like extra little features like docstring automation.

33:55 It helps you on function signatures.

33:58 It does like type of heads.

34:00 You could hover over a function call and it'll tell you the method signature and it will extract that from the library that you're using.

34:08 So if you're using VS Code, absolutely recommend that you download this and check it out.

34:13 There's some cool features that I found, like it does code completion, it suggests parameters for you.

34:19 So if you're using a lot of libraries like Flask or Django or any kind of popular framework that's got type stubs, then this will basically make your life a lot easier because it's going to fill in the gaps for you.

34:34 And as you're typing, you can just press tab and just keep doing auto completion.

34:39 It supports auto imports as well.

34:40 So if you started using a function from a namespace in the standard library or from somewhere else, it'll be like, oh, you probably want to import that.

34:48 It will add the import statement for you.

34:51 It's also got go to reference and go to implementation, which if you've used the VS code extensions in other languages like JavaScript or TypeScript, or you can right click on a function and go to go to reference or go to implementation and it will jump to where that function is actually implemented.

35:09 I know you get that with Python, but this, it uses, I don't know how up to date everyone is on type checkers, but basically there's mypy, which is now part of the Python GitHub organization.

35:22 And then all the big tech companies have written their own.

35:25 Don't know why, but I guess there was like, we have to write our own.

35:28 It's like a rite of passage.

35:30 So Facebook has Pyer, Google has PyType and Microsoft has PyWrite.

35:36 They all more or less do the same thing, but in different ways.

35:39 And this one uses the PyRite type checker.

35:44 But the confusing thing is that PyRite was already an extension.

35:47 So if you had that installed, uninstall it first, otherwise it causes issues.

35:51 And then install PyLance.

35:53 And a couple of other things I called out in the show notes is that there's some non-default settings which you should change to make the plugin a lot more useful.

36:01 So there's diagnostic mode, change that to workspace so that I'll inspect all files, not just the ones that you happen to have open and change type checkings off by default, changes to basic and it will give you more information.

36:16 And yeah, I've been using it and playing around and stuff like that.

36:19 I think there's a few bugs I still need to iron out, but this is a new release.

36:25 It's not open source, so you can't contribute it.

36:28 But I don't know if they'll change that in the future.

36:31 And I think it's because they're planning on using it for some commercial product.

36:34 But we'll see what the news is.

36:35 But yeah, you should download it and check it out if you use VS code.

36:38 Yeah, it looks like it takes the Python extension and just powers it up a little.

36:42 Yeah.

36:43 So I'm guessing you don't, Anthony, you don't run the Vim plugin for VS code?

36:47 No, no, I don't.

36:50 I use this.

36:51 This is the Microsoft Word one.

36:52 I use this.

36:53 It's called a mouse.

36:54 Oh, that's really interesting.

36:57 Does it live in a cage or how do you keep it?

36:59 Do you have to feed it?

37:01 - No, I don't think so. - I was talking to Julian Seker from PyBytes yesterday and he was telling me how much he loves Vim.

37:06 And I said, "So you edit on production then?" And he was like, "How did you know?" - Actually, I'm pretty impressed with the Vim plugin for VS Code, it's really well done.

37:17 - Well, this looks like a cool project.

37:18 And thanks for pointing out the stuff that's off, like the type checking and the diagnostics for being just file-based instead of workspace-based and whatnot.

37:26 I think this adds is multi-route workspaces.

37:29 So a lot of these things come are already in PyCharm, right?

37:32 But like I've got a, I've opened a big directory and I want like two little directories to refer sort of within themselves, right?

37:39 Treat those at the top level for code within each.

37:42 And I don't think that was possible previously, but now it is.

37:44 It also says it's IntelliCode compatible, which I don't know how many people played with IntelliCode.

37:50 I really haven't very much because I mostly stick with PyCharm, even though I had VS Code open while we were talking.

37:56 it uses AI to predict what you're going to type and need.

38:00 So instead of just showing an alphabetical list, it'll say, "Oh, you're doing request dot, you should probably do get." We all just do get, don't we?

38:08 Things like that. So apparently, it's compatible with that as well.

38:11 Yeah, I'm not a fan of IntelliCode, but I've used it a lot in JavaScript, and it kind of like guesses what the variable or the function is, but it gets it wrong.

38:21 Or at least it did the last time I used it, which was a few years ago, but it gets it.

38:25 If one library made a typo or like suggest that, it's like, "Oh, you wanted to do get Getty or something." And it's like, "Oh, no." Yeah, yeah, yeah. Because it scans the GitHub repos, and then it uses that to predict what it's going to suggest for you.

38:39 Yeah, so half the suggestions are normally invalid.

38:42 With a really dynamically typed language like Python or JavaScript, it needs to really import everything and properly understand the modules and how they're constructed to make sensible suggestions.

38:55 Would this be a theoretical suggestion I could actually make? Let's find out.

38:59 Yeah. And I think that's what PyLance kind of gives you is that it uses the type into the, to figure out, and this is why PyCharm is so powerful. It has its own typing system. So it indexes all your code, indexes all your dependencies, and it figures out what the types of responses are, even if they don't have type annotations. And that's how it knows to what's the suggest, like which functions are available, which properties are there and stuff like that. So I think this is basically a step towards that. Yeah, and it's good to see and it will be very powerful. Yeah, very cool. And it has a Monty Python reference.

39:36 Yeah. Well, that's our six. Has anybody got any extra news?

39:39 I have some, but I'll let Anthony go first. Yeah, my book is out in early release. So see Python internals and I got an email from somebody called Guido asking if-

39:50 Oh, I've heard of that guy. I think he does Python.

39:52 I don't know if this is even supposed to be sharing this, but he was like, "Oh, I heard you read this book. Can I have a copy? Because I want to review it and that sort of thing." And I was going to reply as a joke and say, "It's quite advanced how much Python experience you have." But I thought, "I don't know." I know he has a sense of humor, but yeah, my kind of of English sense of humor doesn't work on everybody.

40:18 So no, he's reviewing it and he did send back a comment saying he's gonna recommend it to people who wanna become core developers, which is awesome.

40:26 So yeah. - Oh, that's cool.

40:27 And that's kinda why you put it together a little bit, right? - Yeah, yeah, that was definitely the reason.

40:31 - What's the name of it again?

40:32 - CPython internals.

40:34 And I'm updating it for the PEG parser 'cause that got merged in the middle of the initial release. (laughs)

40:42 So I do have some updates for that.

40:46 So yeah, 'cause a whole bunch of the chapters like show you how the puzzle works and stuff like that.

40:50 So I've been redoing those.

40:52 - Yeah, super cool.

40:52 And you were on a Talk Python 265.

40:55 So pretty recently back in May, talk about that as well.

40:58 So people can dig into that as well.

41:00 Brian, how about you?

41:01 - Just staying out of trouble and working at a nice work.

41:03 - Awesome.

41:04 Yeah, yeah, me too.

41:05 Got to go out and do fireworks with the kids.

41:07 That was fun.

41:08 So for me, I already mentioned the Humble Bundle, but is all you got to know.

41:15 $1,400 worth of Python stuff for 25 bucks.

41:18 It's probably worth the risk.

41:20 - So it's way better than the reverse.

41:22 $25 worth of stuff for a thousand would be terrible.

41:25 - So people will try to sell that, but yeah, for sure.

41:27 Speaking of Python 3.9, Peg Parsers, Python 3.9 beta 4 is out and ready for testing.

41:33 So if that's a thing that you do.

41:35 Anthony, you're probably running that in production already given how much you're on top of it.

41:39 - And I'm a 310 alpha one.

41:41 (laughing)

41:42 - Of course, of course.

41:43 Also, we have a cool course coming at Talk Python Training called Excel to Python.

41:49 So if you've been doing a bunch of stuff with Excel and wanna get into the data science tools instead and do Excel-like things, partner it up with Chris Moffitt.

41:57 We're doing really cool stuff there.

41:58 So people can go get notified about when that course is out, maybe in a month or so.

42:02 All right, are you all ready for a joke?

42:04 - Yes.

42:05 - Anthony, I usually make Brian play the other half of this.

42:09 So you're going to have to do it.

42:11 All right.

42:12 So this is a cartoon.

42:13 The picture is going to be in the show notes.

42:15 You can even view it in your podcast player.

42:17 If you allow it to show images from Scott Hilburn.

42:19 I couldn't find the original place to link to.

42:22 So I just put a, an image up here and it's two computers, a laptop and a desktop looking at each other.

42:27 There's a baseball cap on top of the laptop and he's got a little like computer arms up and he's like sweat.

42:34 He's like, I can't get it off.

42:38 Anthony, what's the problem?

42:40 - And the other computer says, "Dude, that's because your caps lock is on." - Ah, it's locked on.

42:46 - Get it off.

42:47 Yeah, okay, anyway, so I thought that, that one made me laugh, especially the picture.

42:52 So check it out, Jim Podcast Player.

42:53 - Yeah, I can tell why he's trying to get it off too.

42:56 It looks like a red hat.

42:57 - It definitely, yeah.

42:58 Yeah, that's probably like Windows Vista, got red hat on it and can't get it off.

43:02 - Cool, well, thanks a lot guys.

43:05 - All right. - Yeah.

43:06 - Thanks. - Great to be here, thanks.

43:08 Thanks as always, bye everyone.

43:09 - Thank you for listening to Python Bytes.

43:11 Follow the show on Twitter @pythonbytes.

43:14 That's Python Bytes as in B-Y-T-E-S.

43:17 And get the full show notes at

43:20 If you have a news item you want featured, just visit and send it our way.

43:25 We're always on the lookout for sharing something cool.

43:27 This is Brian Okken, and on behalf of myself and Michael Kennedy, thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page