Python Bytes - #63 We're still on a desktop GUI kick

Episode Date: February 1, 2018

Topics covered in this episode: A brief tour of Python 3.7 data classes SQLite [The Databaseology Lectures - CMU Fall 2015] dryable : a useful dry-run decorator for python PEP Explorer - Explore Py...thon Enhancement Proposals TKInter Tutorial Extras Joke See the full show notes for this episode on the website at pythonbytes.fm/63

Transcript
Discussion (0)
Starting point is 00:00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is episode 63, recorded January 31st, 2018. I'm Michael Kennedy. And I'm Brian Ocken. And as always, we've got a bunch of stuff lined up for you. Before we get to it, let's just say quickly thank you to DigitalOcean for making this show possible. Thank you, DigitalOcean. If you want to check out what they're offering, do.co.python. I'll tell you more about them later.
Starting point is 00:00:23 Right now, I want to hear about a little bit about what's coming in python brian we've already talked about uh data classes coming up in python 3.7 already and um i was curious about you know exactly what that means to how it'll be to work with them and stuff and and uh and anthony shaw put together a tour of of how they work and it's a it's pretty quick read but it's but it's a pretty good thorough understanding of it. I guess it's called a brief tour of Python 3.7 data classes. And there's some exciting things. One of the things is there's a lot of the default magic methods that I'll put in place are like init and represent or repper.
Starting point is 00:01:03 I don't know how you say that. And the dunder stir and dunder equal. The equal one is the thing that I think is really kind of cool is that it's going to compare all the attributes in order. So if all of the elements of your data class are equal to another object with the same elements, they will be equal. And that's not something that's normal by default. So that's good.
Starting point is 00:01:29 Yeah, actually, that's really cool. And I wonder, I don't know, there's a couple of things that are interesting to me here. One is the default value stuff, the way that you can configure the fields, the fact that there's type annotations coming as basically, are those required? It looks like they might be required, not just optional. They are required, but if you don't know what a type will be, there still is the,
Starting point is 00:01:54 in the types, there's an any type that you can use. Yeah. So basically that's like the void star or whatever. Like, I have no idea what this is, just it's a thing. I mean, this is Python. So a lot of times you want it it to be generic you don't know what the type is going to be yeah yeah that's right that's right it's pretty interesting so i do like these the other thought i had about these looking through this is i wonder if this means the name tuple is less cool these days what do you mean well one of the things i think that's nice about the name tuple is you can basically create a type and you say it has these fields and then you have sort of typed access to
Starting point is 00:02:32 it in the editors. You hit dot and you get a dropdown of all the available elements of that thing. You can make it read only, which is potentially nice. What else? It has a nice string representation as a nice hash and equals operator, right? All those types of things. Every one of those comes in data classes. And if you put a frozen on the data class attribute to say, actually, this is read only, then it also implements the hashing. It has the immutability feature. Once it is created, it looks like it is the sort of equivalent of a named tuple, but it's richer in the sense that you can have like default generated values. It has, it just seems a little richer than a named
Starting point is 00:03:12 tuple, but it's the usage is pretty much the same. I think in my case, I probably will use it. I'll try to use it more to see how I like it. But I mean, right now I use named tuples quite a bit and they're, yeah, they're very, they're very terse. There's, you know, a couple lines of code and you've got a new type. Yeah. The one thing I do see here is like with name tuples, you can literally on one line have a type that it takes six arguments. Whereas this one, you know, it's certainly more verbose, but once it's defined, I feel like basically the use case is like this is a superset of named tuples unless I'm missing something. Yeah, definitely think in the use case, a lot of places where named tuples are being used, data classes will be used instead. It'd be interesting to see if there's any different performance for data classes versus regular classes.
Starting point is 00:03:58 I think you can say use slots. Is that possible? I think that might be a thing. That I'm not sure. Anyway, if you can do that, that would actually have a really interesting impact as well, because that would probably use less memory than name tuples. At least my testing has shown that it does. Well, I'm sure that there will be somebody that goes out and does some performance analysis to give us that answer.
Starting point is 00:04:18 Yeah, it's a call to the audience indeed. Very, very cool. So these are coming and that's pretty neat. Hey, I have another piece of news for you related to this. Okay. So Python 3.7, development on it
Starting point is 00:04:29 is like sort of frozen in the sense that it's now out for testing and for usage, but no new features are being added to it. So it's kind of frozen. And Python 3.8 development
Starting point is 00:04:39 started yesterday. Wow. Yeah, so I haven't started testing with 3.7 yet or doing any of that. Have you used it at all yet? No, I've thought about it, but I haven't done it now. Yeah. Definitely something I want to get started on here pretty soon because I think it's due to drop in like June or something like that. Yeah. It's in like a trial period to make sure the
Starting point is 00:05:00 world doesn't break when it gets released. Because could you imagine the pressure? But yeah, it's supposed to officially come out in June. But it's kind of gone into its testing mode, which is pretty cool. So if I ask you what was the most popular database in terms of deployments, what database would you guess? Oh, I've fallen for this before. I'm going to answer Excel. Excel. Is that actually, you know, I don't know. This one that I'm about to say, it was very likely to give even Excel a run for the money. So everybody who has Python has SQLite, right? It's baked in. There's a whole bunch of things that are interesting about SQLite.
Starting point is 00:05:36 So it's like an in-process database. If you want to do something relational, say with like SQL Alchemy or something, but you just want to ship some, a little app. You don't want to deal with like a client server model. SQLite is so super nice for that, right? You just have like a little data file. And I think we maybe talked about this a little bit before
Starting point is 00:05:55 in a couple of shows back, but one of the listeners said in this thing, this series from Carnegie Mellon University called the Databaseology Lectures. So there's a bunch of databases covered there and actually quite a few interesting ones. And the idea is these are like hour, hour and a half long academic lectures by the creators of various databases about the internals of how they work. And I think it's more or less like a CS sort of either speaker series or actually a course.
Starting point is 00:06:25 I'm not sure. But they got a bunch of Luminary folks to come and speak about it. And it's pretty cool. So they have like the guy. That sounds like an exciting date night. Oh, yeah. Yeah. My wife was pretty excited when I suggested that.
Starting point is 00:06:38 No. So there's Wired Tiger, which became the foundation of the storage engine of MongoDB. They had that before it became engine of MongoDB. They had that before it became part of Mongo. The one that I wanted to call out is the one by Richard Hipp, who is the creator of SQLite. And it's like this deep look inside the architecture and trade-offs and design decisions of SQLite. And so if you're interested in databases, you're interested in how SQLite works, there's a bunch of optimizations and trade-offs you can make around durability versus performance. There's a bunch of deep dive stuff into here. So I thought that was pretty cool to highlight.
Starting point is 00:07:11 I'll definitely check that out. I also noticed that they've got even SAP and Oracle. That'd be interesting. Yeah, something to do with Berkeley DB in there as well. So yeah, it's quite cool. Yeah, but there's just so much I'm not really sure I want to try to cover it but if you want to look inside of like how do the b trees mapped disk and how do they deal with like power failure transactional durability and all that kind of stuff you want to see a deep look inside of that for databases in general and sqlite in particular you check it out there i guess one just as a teaser one interesting fact that came out of there is SQLite is shipped as a single C file.
Starting point is 00:07:48 Yeah, that's cool. I don't know how, like two million lines? I don't know, like some insane number of lines. They don't develop it as a single. No, no. There's some process, some mechanism that like detangles all the, you know, include statements and the various compile orders and all of that stuff. And it like generates this one huge file with like no dependencies.
Starting point is 00:08:11 But it's pretty wild to think of such a program as created that way. It's interesting that it's intentionally no dependencies. The whole thing is a little bit unusual, the way that the guy has created it and run it. Like instead of, he was like well open source is good but actually i just want to make it like nobody this is a thing that just is the world and so he made it put it out there under common domain or what's that called anyway where
Starting point is 00:08:38 you just say like it belongs to the world i relinquish all ownership of this thing it is just now public domain, public domain. Yeah. So it's pretty interesting. Yeah, it is. Do you know what else is interesting? Testing your code before you take down the system or you charge a credit card and you didn't want to. Yeah. Did we get this from a listener or a camera? Yeah, this definitely came from a listener. I can't remember who, maybe I'll pull that up while you're having a look. Okay. Well, this is a project called Dryable, a useful dry run decorator for Python. And the idea is that there's some times where you want to run your entire application, but there's pieces of it that you don't want to run all the time.
Starting point is 00:09:21 Like in their example, they've got, if you're accessing an outside database with requests or something like that, you can turn that off during your dry runs. And I really like how generic this is. So basically, you put a decorator. It's a dryable decorator you put on top of a function. And then when you set the dryable state to true in your code, those functions just don't do anything. And then they also have the option of specifying a default return value. So during your dry runs, if the function that you're turning off is supposed to return something or else the rest of your code is just going to break, you can specify that there.
Starting point is 00:10:08 And for testing certain systems, I think this is an awesome idea. It's pretty cool. It's pretty easy to start. It's almost like if I wanted to set up the mocking story for my code by using decorators and I could run it just even outside of a test framework, like what would that look like? It looks like this drivable thing, right? The intent, I think, is to be able to just leave this stuff in your code. So it's a very minimal impact.
Starting point is 00:10:34 And then you can just, if you want, you can just leave it there so you can always be able to do dry runs or something. Yeah, in your test code, you just say driable.set true, and then it just goes in the sweat so one of the things i was wondering about when i saw this i agree that it's cool and i i definitely like it but one of the things that i was wondering is like we have mocking and these other mechanisms for stubbing out stuff like where do you see this fitting in versus not a lot of times people and i i agree mocking is definitely, mocking and monkey patching is often used for definitely for testing stuff.
Starting point is 00:11:13 But like, I don't know, for example, you could put together, we were doing different GUI applications we were showing the other day. If you wanted to attach a GUI to a database system, you could have a mocked up database set to just let people play with the user interface. And that's not really a testing thing. It's you're just using something with some dummy data in the back end. Something like that would work.
Starting point is 00:11:40 I see. If you're trying to build out the UI and you don't have the data yet, it would be really nice to just go, and here's some data to work with until we get there. Yeah, definitely. Yeah, okay. That's pretty cool. So I told you about DigitalOcean at the top of the show, and I'll give you a little more details. They actually have some super exciting news, maybe a week, week and a half ago, two weeks ago, I can't remember. But I actually spent a lot of time upgrading a bunch of servers because DigitalOcean is awesome. They actually went and said, you know what,
Starting point is 00:12:08 all that money that you're paying for the servers, we're just going to double all the things. You have one gig of RAM and you're paying us $10 a month. All right, now you get two gigs of RAM. You have one CPU and you're paying a certain amount. Now you get two CPUs or two to four. So they basically not, not everything. CPU is not quite as much, but certainly, you know, disc size with SSDs,
Starting point is 00:12:31 the Ram, the, to some extent, the CPUs are basically doubling everything they offer. So now you can get like a server with a gig of Ram and a CPU and 30 gigs, 50, I don't know, 50 gigs of SSD for $5 a month.
Starting point is 00:12:44 How insane is that? Wow. Yeah, exactly. So anyway, it's really cool, the new pricing that they put out. So definitely drop over do.co slash Python and check that out because if you thought it was good before,
Starting point is 00:12:57 like literally they doubled most of the things for most of the tiers. That's great. Yeah, so really nice. And Python Bytes now delivers itself just a tiny bit faster and has a few more gigs of RAM to do it with. Well, that's good
Starting point is 00:13:10 because our listeners are going up. Right, we got to keep up with the demand. Thank you, everyone. Speaking of demand, we got actually a lot of listener feedback for this show. And I think that that was really great. Like, please keep the recommendations
Starting point is 00:13:22 coming in on Twitter and email and so on. Have you noticed I've been on this gooey kick lately, Brian? We kind of knew this was going to happen. We claimed that there weren't any good solutions. And then people told us. Yeah, I still mostly stand by that. But there are people doing really cool things. And I just want to highlight them.
Starting point is 00:13:41 So a guy named Victor Domingos said, hey, look, I'm not really much of a programmer. I kind of like an engineer or something. You know, he was doing something else, but he needed to do some program to build this thing, right? But I disagree with that statement. I think he's quite a programmer building these things. So he sent us three examples of some apps that he built in Python. And I don't know, do you click those and pull them up, Brian,
Starting point is 00:14:04 and see the pictures? I'm trying to pull up one now. Yeah. So what's really nice is it's all screenshots, which by the way, if you have a UI framework and you want people to admire your UI framework, screenshots. Yes. Pictures, please. Just describing how awesome it is in text doesn't actually make it awesome. But these look like rich, interesting applications. And I definitely think what he's doing here is quite neat, especially the first and the second one that we've linked. So we've linked to three.
Starting point is 00:14:31 This is crazy. PT Tracking, it's got both the desktop application, which looks nice. And an iPhone version. And an iPhone version. Yeah, it's pretty interesting. I mean, like I said, this guy built some really powerful stuff, right? Yeah, looks great. What's even better is it's open source, right? This is TKEnter code. He's like, look, you're giving TKEnter a bad rap. This is actually could be more nice looking if it's built the right way. And by the way, here's three open source apps I built that you can check out with screenshots, by the way, which is very nice. So I just want to highlight that,
Starting point is 00:15:06 say thank you, Victor, for sending these in. Share the links he sent because they are pretty inspiring and they're working examples. I did not know you could make an iPhone app with TKinter. I still don't even know how that works. I don't either. Maybe I'll try this out.
Starting point is 00:15:18 Maybe there's some kind of PEP for it. Like a PEP, what is that? PEP 7225, make Python build desktop or mobile apps on iPhone. Is that what it is? What if there's like a way you could figure this out that we could settle this debate? There's PEP Explorer and it is by Anthony again, Anthony Shah, that we gave him credit on the first article that we talked about. But PEP Explorer, explore Python enhancements with a web interface.
Starting point is 00:15:47 It's got a search function and you can look at all sorts of stuff. There's even in the status, I don't quite get all the status ones, but there's an April Fool status, which I didn't know about. That's pretty awesome. In 2009, they pretended that BDFL was retiring. It probably just scared people, actually. That's really what happened. Yeah, so not only do you find the PEPs that were accepted, but you can search and say, show me the ones that were either deferred or rejected.
Starting point is 00:16:13 You probably will learn a lot of interesting stuff by seeing what is rejected and why. Yeah, and then the ones that are still in draft form and everything. One of the things I wanna, I had already picked this and then I was playing with it because the data classes that we talked about earlier, I cannot find on this little cool tool here. So I'm not sure what's going on with the 3.7 stuff. Maybe 3.7 just isn't in here yet.
Starting point is 00:16:36 Yeah, maybe. And this is a search engine sort of thing with data backed on GitHub, right? And so if anybody wants to say, oh, you're missing this one, PR. Yeah, so nice people do fix it and do a PR. I just am going to call them out on Python Bytes and say it's broken. This one doesn't work. It's not there.
Starting point is 00:16:55 And I can't do a PR right now because I'm recording a podcast. Yeah, definitely. Yeah, yeah. Nice work, Anthony. Enough to get a double feature. Very, very cool. So I want to round this out
Starting point is 00:17:04 with just a little bit more UI stuff. If I'm going to show you all those pictures of cool apps that Victor built, the other thing I want to sort of pair with that is a TKinter tutorial from this, we got on Twitter as well from at like geeks. And it's basically here's how you go through TKinter and create your first GUI application. You don't really build anything too complicated or too advanced. It's more like, let's put some labels and buttons and combo boxes and progress bars on and see what that looks like, right? It's still like a decent distance from what Victor had built.
Starting point is 00:17:36 But if you were inspired by topic four, maybe topic six can help you take some steps in that direction. Yeah, okay. Yeah, it's pretty comprehensive. Like it really covers most of the widgets and how to use them and stuff like that in Python. So yeah, pretty cool. This may be the final thing we say about it
Starting point is 00:17:52 or maybe my own news actually will cover one more GUI thing. Yeah. I think that we'll probably hear some more GUI things coming up in the future. Yeah. I'm okay with that. I am too. And I think this is great.
Starting point is 00:18:03 I think the other area that's looking really strong, the that i talk to people about this is wx python yeah what i didn't realize is wx python has a project called wx python phoenix where it was reborn from the ashes of wx python and there's like two versions of it sort of so there's like a more modern version that i like conflated with the older version okay didn't know about that yeah i didn't either but the thing i'll tell you about uh in a second did how about you any uh any other personal news you got going on anything cool not right now nice for me this is like the week of the recording the recording so i'm recording uh six podcasts talk pythonPython, Python Bytes. I was a guest on a podcast and also a webcast. So I did like an hour and a half webcast where I rebuilt PyPI in MongoDB, which was really fun.
Starting point is 00:18:55 Wow. So it was really, really cool. And I even created this fake database with like, you know, hundreds of thousands of records to make it act real. It took like 15 minutes for the program to actually generate the database, but that was okay. It was still good. Anyway, so that was fun. I'll put a link in there. This weekend, some friends were over and they're like, hey, I'm trying to build this little script and it's almost working. Can you help me? And I'm like, oh, this is a cool little CLI, but do you know what would be better is if it was a GUI. It's like, yeah, I know, but you can't do that in Python.
Starting point is 00:19:26 Can you like, yeah, hold on. Like let's pip install GUI, G-O-O-E-Y, that thing we already talked about. And that thing is slick. Let me tell you, basically you create one of these argument parser things from GUI and you say, it takes these parameters and then you say, get the parameters.
Starting point is 00:19:41 And that actually shows the UI with all the widgets filled out and the names of the types. Like one is a combo box it has these three items that like that's your argument then it becomes just a combo box it really is like just a few lines of code it's awesome we've been getting a lot of people that have been using gui show us their screenshots of something they made with it in just a few minutes and that's pretty awesome i really think the bang for the buck is quite high on gui right now. And that's WX Python, by the way. Also, a quick announcement on the courses. I have a bunch of courses coming up and more of them are getting planned all the time. It's really fun. But I just launched a sort of business option team purchase page. So all the bundles and the courses and stuff
Starting point is 00:20:21 at TalkPython Training now have a buy this for your team. And if you pick like a, however many people are on your team, it'll automatically apply like enterprise discounts and all that kind of stuff. So if you want to go in there and say, buy this for 10 people, it's all totally self-service now. Wow. That's great. Yeah. So trying to make it easy for people to get more of that Python knowledge. Yeah. All right. Well, thanks Brian for finding all these things and sharing with me yeah thank you yeah bye thank you for listening to python bites follow the show on twitter via at python bites that's python bites as in b-y-t-e-s and get the full show notes at pythonbytes.fm if you have a news item you want featured just visit pythonbytes.fm and send it our way we're always on the lookout
Starting point is 00:21:03 for sharing something cool. On behalf of myself and Brian Ocken, this is Michael Kennedy. Thank you for listening and sharing this podcast with your friends and colleagues.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.