Transcript #242: from lib import * but less
Return to episode page view on github00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
00:04 This is episode 242, reported July 14th, 2021. I'm Michael Kennedy.
00:11 And I'm Brian Arkin.
00:12 Hi, and I'm Al Swigert.
00:13 Hey, Al. Welcome, welcome. Before we get to introduction with you, I just want to say this is brought to you by our courses over at Talk Python Training and Brian's book.
00:23 But first, let's just hear about you, Al. Tell people who you are if they don't know.
00:27 Hey, I'm Al Swigert. I'm mostly known as the author of Automate the Boring Stuff with Python and a bunch of other Python and programming books for beginners.
00:36 So all my books are released under a Creative Commons license, so it's free to download and share them.
00:42 You can get them at inventwithpython.com.
00:45 Nice.
00:45 Yeah, yeah, fantastic. I would say the Automate the Boring Stuff has certainly been well received.
00:50 Yeah.
00:51 I hear it quoted a lot, for sure.
00:54 Brian, do you want to get us started or what?
00:55 Yeah, I'll just get us started.
00:57 So, no, so Just, I saw a tweet by Jeff Triplett that mentioned Just as a replacement for Make, so I needed to check it out.
01:08 So, and it's like super cool.
01:10 Make, for people who don't know, is a thing that you can type, basically you type Make, and then it automates a bunch of commands.
01:16 Like if you've got a seriously complicated build link process, it could be embedded into a Make file, and then you just type Make, and that happens, right?
01:23 Right, right.
01:24 And it's, I don't know what the history of Make really is, but I used it a long time.
01:28 I've been using it for decades for, one of the things it does well is convert, like if you've got, take all your .c files and convert them to .o files, and then combine your .o files, and all the build process for the C tool chain.
01:44 But you can do it for, you can really do it with any language.
01:47 But people have like abused it, and so have I.
01:49 Even Python projects often use Make files, because Make is often around on Unix-like environments.
01:57 And so having Make file around, you can use it just sort of to automate some of your common tasks, like make release or something.
02:04 To push your, to do all the commands you need to do to do a new release of a project or something.
02:10 But there's problems with it.
02:12 And so Just is a replacement for it.
02:15 And it's written in Rust, so it's pretty fast and clean.
02:21 Well, actually, I don't know if it's clean.
02:23 I haven't looked at the source code.
02:24 But it's really easy to use.
02:27 It's not C, it's got to be better.
02:29 It kind of looks like mail files.
02:31 So, yeah.
02:32 I went ahead and installed it both on a Mac and Windows today to try it out.
02:37 One of the things I really love about it is, it's not, the main part of it is to try to automate commands.
02:44 It's not about, you can build like, you can use it to build things and have recipes to make all your .c files into .o files if you want.
02:54 But the real power is to use it in the way we've been abusing Make before.
02:58 Because you can do some cool things.
03:01 Like, one of the problems with Make always has been the rules have to be on the, or the recipes have to be defined on the left column, leftmost column.
03:13 And then you have to like have a tab for the commands.
03:17 Well, I mean, often I have my editor set up except for Make files to replace tabs with spaces.
03:24 Just works just fine with spaces.
03:28 I love that.
03:29 And also you can pass commands, pass arguments to commands, command lines, stuff like that.
03:35 That's cool.
03:36 It's super cool.
03:37 One of the neat things, I don't know where it is in the documentation here.
03:42 Oh, you can use arbitrary languages.
03:44 You can even do like a Python command within the Just file.
03:49 So it's a...
03:51 That's cool.
03:51 You can do some neat things.
03:53 Or parole or whatever.
03:54 For people listening, you basically declare the languages you want to use.
03:57 And then you can implement code, like print or console.log for JavaScript or whatever.
04:04 Right.
04:04 This actually seems like a bad example because it's actually listing the recipe name as the language name.
04:10 And you don't have to do that.
04:11 So this Python here could just be foo or something.
04:14 Oh, I see.
04:15 So the thing that's important is the shebang.
04:18 Yep.
04:18 The shebang tells just which language to use.
04:23 So this is pretty neat.
04:25 I've started using it right away.
04:26 And I think I'm going to keep using it.
04:28 It's great.
04:29 Well, one thing that I got out of this that's interesting.
04:31 Scroll down to where it has like the how to get it.
04:33 You'll see like a whole bunch of links.
04:35 If you go down that page.
04:37 A little more.
04:38 Keep going.
04:38 Installation.
04:39 Yeah, I think so.
04:40 There's a section.
04:41 Oh, no.
04:42 Oh, yeah.
04:42 There you go.
04:43 There's a bunch of...
04:44 It shows you all these different package managers that'll give it to you.
04:47 So if you want to get it from Rust, you can use Cargo.
04:49 On a macOS, there's Homebrew and Mac ports.
04:51 If you want it on Windows, they interestingly recommend Scoop, which I've never used.
04:56 I've only used Proclity.
04:57 So I don't know.
04:59 I feel like there's like ice cream themes or something for the Windows world.
05:02 But yeah, those are pretty interesting.
05:03 I was going to be snarky and say, do you require Make to install Just?
05:08 Yeah.
05:10 So I got no problem using Brew install for on my Mac, but I'm not going to install Scoop.
05:17 for Windows.
05:18 I don't have any other need for it.
05:20 So there is prebuilt binary.
05:22 So I just used the prebuilt binary for Windows.
05:25 It worked fine.
05:26 Yeah, this looks really great because my experience with Make has been to just run the basic make
05:32 command to build something.
05:33 And if it works, that's great.
05:35 And if it doesn't, I have no idea what to do because I feel like my knowledge of Make is sort of like my knowledge of CSS, where it's just been built up from little bits of knowledge over the years.
05:45 And I've never formally sat down and read through all the documentation.
05:49 100% JIT learning, like just enough time that you needed.
05:54 Yeah, exactly.
05:56 Yeah.
05:56 Like, I actually have never really understood why phony targets were needed.
06:01 And this discussion in the readme of this, of Just actually talks about why phony is needed in the first place for make files and why you don't need them for Just.
06:12 So it's kind of interesting.
06:14 Yeah, very cool.
06:15 Very cool.
06:16 We'll move on to the next item.
06:18 A couple of comments for Al out there.
06:20 Teddy.
06:21 Hey, Teddy in the live stream says, love to automate the boring stuff.
06:23 How we learn Python.
06:25 Dean says, always recommend it to get started.
06:28 Great fan.
06:29 So, yeah, that's pretty cool.
06:30 Awesome.
06:30 Hey, thanks.
06:31 I always love hearing that.
06:33 You bet.
06:34 All right.
06:35 I love to hear from our fans of the show.
06:38 And so Roman Wright, who worked on Beanie, the, I believe, Pydantic-based model query for ODM for MongoDB, recommended something else.
06:51 This time we already covered Beanie, something called strong typing.
06:55 So this is a decorator.
06:57 This is from Felix the Sea.
06:58 It's a decorator which checks whether a function is called with the correct arguments.
07:03 So if somebody goes and puts type annotations on their code, that's cool.
07:09 The editors like PyCharm will say, you're doing it wrong when you're doing it wrong.
07:14 Or they'll give you autocomplete and information on the arguments and so on.
07:17 But, you know, Python, that's like a hint, right?
07:20 Called type hints often.
07:22 Because it's a hint.
07:23 It is not a requirement.
07:24 And so if you want to make sure that certain types match up, basically, you can use this decorator.
07:32 And there's not a lot to this one.
07:33 But go over to the read the docs.
07:36 There's a stay strong little character there.
07:39 But the idea is if you had this thing that was like a multiplier, took an a int and a b int, you could pass other stuff.
07:45 But if you pass, like if you could pass like three and four to multiply, but if you pass like hello world, it's just going to try string times string, which there's probably a cool Watt outcome that we could get there.
07:57 But that's not what happens in Python.
07:59 We get a type error, right?
08:01 If you do a string times a number, you get a pretty interesting outcome.
08:05 And this is something of a Watt.
08:06 If you do like hello times four, you get hello, hello, hello, hello four times, which has always been weird.
08:12 When I learned you can multiply strings, it kind of freaked me out.
08:14 But I've come to find it useful.
08:15 So what do people do?
08:17 Well, they're like, well, this won't stand.
08:19 We need to check the type.
08:20 So we're going to say if is instance the first parameter and an int and is instance the second one.
08:27 We can do it.
08:27 Otherwise, we're going to report an error.
08:29 Don't do that.
08:29 Instead, what you can do is you can use this match typing decorator.
08:35 And you can just say at match typing and it's going to take the arguments based on the type
08:41 hints and validate them.
08:42 So if you pass in the right one, great.
08:44 It'll give you an answer.
08:45 If you pass in something that does not match the type annotations described, it'll say it'll
08:51 raise a type mismatch exception.
08:53 And this can be nested down.
08:54 So for example, one of the examples is it takes a list and let's see, takes a list, which
09:01 is a union of strings, ints, and tuples.
09:04 So if you give it a list that has either a string, int, or a tuple mixed heterogeneously
09:11 into the arguments, it'll take that just fine.
09:13 But if you give it some other type, like a list that happens to contain one of the elements
09:17 as a date time, it'll give you this exception.
09:19 So it's not just, oh, it took a list.
09:21 It has, you know, like the transitive sort of property of analyzing the types is validated
09:27 there.
09:27 So pretty interesting.
09:28 What do you two think?
09:29 Yeah.
09:29 So the difference between this and something like mypy is that this operates at runtime,
09:34 right?
09:35 Right.
09:36 Exactly.
09:36 Because you could do all the mypy stuff you want.
09:38 And if people don't run it, well, you're not going to get any information out of it,
09:41 right?
09:42 Yeah.
09:42 That was something that I was really surprised to learn when I first learned type hinting was
09:45 that really Python's type hints don't really affect the runtime code.
09:51 at all.
09:52 It's just set up for static source code checkers like mypy.
09:55 So it doesn't turn Python magically into a statically typed language.
10:01 It's just for these static source tools.
10:04 Yeah, exactly.
10:05 That's mypy is.
10:06 And this is kind of the other side of that, right?
10:09 This is the runtime one.
10:11 So maybe you would use this in the case where you're building a package or library and it's
10:15 you've done everything correctly, but someone else is consuming it potentially incorrectly
10:20 and you can't control whether the world uses mypy or not, right?
10:24 Yeah.
10:24 You just wrote a library.
10:25 And so you could use this on say the boundary of your library, not everywhere, just on the
10:30 boundary to make sure the stuff that goes in and out is valid.
10:33 And this would be really helpful for stuff that I work on because usually I'm just sort
10:37 of writing code ad hoc that sort of does this runtime checking.
10:40 But it's really nice that I could just throw in a function decorator and just add that capability
10:46 and that's all I have to do.
10:48 Yeah, absolutely.
10:49 Oh man, yeah.
10:50 Yeah, this is great.
10:51 Well, so clearly this is adding code, your code, right?
10:55 So I'm just curious about the performance.
10:58 Yeah.
10:59 So is Teddy.
10:59 He out there in the live stream asked, do you know if there's any potential lost performance
11:03 since it's running at runtime?
11:04 I'm going to say I am certain there is lost performance.
11:09 Unfortunately, in Python, calling a function is a relatively slow operation.
11:15 And doing a decorator is effectively calling a function.
11:18 So it's got to be slower.
11:19 That's why I would say put it just on the boundaries, you know, something like that.
11:24 But I mean, the alternative is if you actually want to do these tests, if you actually want
11:28 to do that validation, it's an if statement and multiple is instance of all over the plate,
11:34 right?
11:34 So if you're going to do that validation anyway, you're already calling.
11:37 It's just not on the outside.
11:38 It's on the inside, right?
11:39 So good question.
11:41 I don't know.
11:41 Yeah.
11:42 Another question from Ben Lindsay.
11:44 Do you know how this compares with Pydantic's validate arguments decorator?
11:48 I don't know, but I'm a big fan of Pydantic and the validate arguments decorator is exactly
11:53 the same type of thing that we're talking about.
11:56 So for example, like you should put the at validate arguments.
11:59 The thing is that I did notice somewhere that, yeah, here it is.
12:03 Like this validate arguments decorator is in beta for whatever that means.
12:07 It won't be concrete until V2 Pydantic.
12:11 But that may well be more, more concrete and more formalized than this one.
12:18 Right.
12:18 Although this is more standalone, right?
12:20 You don't necessarily.
12:22 It feels like a little tiny thing that you just plug in on there.
12:24 Pydantic is doing a lot.
12:26 I'm a fan of Pydantic.
12:27 So yeah.
12:28 Good question, Ben.
12:28 All right.
12:29 Al, you got the next one, right?
12:30 Yeah.
12:31 So I have a new book out.
12:34 It just came out at the end of June.
12:36 It's called The Big Book of Small Python Projects.
12:39 So a lot of my books have been for people who are total beginners or relatively new to not
12:46 just Python, but to programming in general.
12:48 Generally people who have boring stuff.
12:50 Yes.
12:50 Yes.
12:51 Oh, man.
12:53 So much boring stuff.
12:54 Actually, you have books on games and things as well.
12:58 Yeah.
12:58 Yeah.
12:58 That's the two approaches I have to tricking people into learning how to program is getting
13:04 away from Excel and then also learning how to make video games.
13:08 Seems to be really common pathways into programming.
13:11 So I've also noticed that with a lot of beginner tutorials, people learn the syntax and they
13:17 learn all the concepts like loops and variables and things like that.
13:20 But when it comes to actually working on their own projects, they're sort of stuck and they're
13:25 just left staring at a blank editor and not really knowing how to proceed from there.
13:30 And a lot of people will give them usually the two bits of advice that people get are, oh,
13:35 you should work on open source projects or just read the code for open source projects,
13:40 which is actually pretty terrible advice for beginners because a lot of open source projects
13:45 might not be well documented.
13:46 They're written for professional software engineers.
13:50 There's a lot of concepts.
13:52 Yeah.
13:52 There's a huge difference between something that is absolutely polished and meant to be
13:56 used in many situations in the real world.
13:59 Like you might learn a lot by looking at Django, but most of the time you'll probably just be
14:03 confused.
14:03 You're like, why is this so complicated?
14:05 Well, it's so complicated because, you know, a million websites use it in weird ways and that's
14:10 why it's complicated.
14:11 That's not a good learning tool per se.
14:13 Yeah.
14:13 Especially for someone who just learned about, you know, how to call functions and how to create
14:18 classes and pretty basic things like that.
14:20 So I spent, I think, I think I was working on this on and off again for about two or three years,
14:26 but I wanted to create a collection of small little programs, mostly like games or puzzles
14:32 or little simulations or things like that, where they were all just really simple and easy for
14:38 beginners to read through and then they can understand, oh, this is how all of these concepts
14:43 I learned get applied to an actual program that does something.
14:46 So these aren't code snippets.
14:48 They're not just like tiny little functions or things like this.
14:50 This is programs that you can actually copy the code yourself and then figure out how they
14:56 work.
14:57 So I have about 81 of these projects altogether.
15:00 They're all under, I set a limit of 256 lines of code, just as an arbitrary power of eight to
15:08 set it to.
15:09 And they are all text-based games.
15:11 So they're fairly old school looking, like a lot of the games that people were programming
15:16 in basic in the 1980s and 90s.
15:19 But the plus side of that is that all of the games are really simple and you don't have to
15:26 install additional libraries or modules or things like that.
15:29 You can pretty much just type the code in and it just uses the Python standard library
15:36 for all of this.
15:38 I have a few of these programs that use a few other modules as well.
15:41 But for the most part, you can get pretty far with just text and just ASCII art.
15:46 And also, even if you already know Python, these programs are great just for ideas of if you
15:52 want to learn another programming language and just get used to how things work in that.
15:56 You could find the idea for a blackjack game from this collection of programs or this birthday paradox
16:04 calculator and all sorts of these little projects right here.
16:08 And of course, this book is also freely available online at inventwithpython.com slash bigbookpython.
16:16 I'm starting to get reviews coming in on Amazon and they seem to be pretty positive.
16:20 So I'm really hopeful about people just being able to take the next step in learning to code with this book.
16:28 Yeah.
16:28 Cool.
16:28 Cool.
16:28 Yeah.
16:29 And then the other book that I had that came out in November is Beyond the Basic Stuff with Python,
16:36 which is sort of the follow-up book to automate the boring stuff with Python.
16:40 I had a lot of people who were asking me like, oh, I really like to automate.
16:43 What should I read next?
16:45 And I had like some things that I would tell them like fluent Python is a really great book,
16:52 but it's also like 800 pages or 800 pounds or something.
16:56 It's a really huge book and the information in it is great, but it's really intimidating to
17:02 take this book and it's like, okay, read this one next.
17:05 So I wanted to cover a book that had sort of the best practices for a lot of like software
17:13 engineers.
17:14 So there's sections on like how to name your variables or how to do code formatting.
17:19 And then I talk about the black code formatting tool.
17:22 I talk about type hints and how to write documentation.
17:25 I have a very superficial coverage of Git and GitHub and how to use version control.
17:33 And just, you know, and I even dive into like, what exactly does Pythonic mean?
17:38 Spoiler alert, Pythonic basically means anything the person you're talking to wants it to mean
17:45 at the time.
17:45 But yeah, just sort of a lot of the things that you don't really get in your typical
17:50 hello world tutorial.
17:51 These are the sort of tidbits that you would pick up with experience over years of experience,
17:58 I guess.
17:59 but I just wanted to collect all of that advice and information and best practices into
18:03 a single book.
18:04 So yeah, that's also available online at the inventwithpython.com website.
18:08 Cool.
18:09 A couple of comments from the live stream.
18:11 John Dehan says, beyond the basic stuff was great for learning to do things Python way.
18:16 And wow.
18:17 Great to see you, Mr. Swigert.
18:19 Seems like only yesterday I was promoting your last book at Bay Piggies from...
18:23 Oh, hey, Neil.
18:24 How's it going?
18:24 Cool.
18:26 Yeah.
18:26 Yeah.
18:26 Very cool.
18:27 Congrats on the books.
18:28 Brian, let's go.
18:30 Let's talk about something completely different than books.
18:32 Like notebooks.
18:35 Yes.
18:36 Let's talk about notebooks.
18:38 Thanks for popping that up.
18:39 Yeah.
18:40 So this was another suggestion.
18:43 This suggestion came from David Nicholson.
18:45 Thanks, David.
18:47 I thought we'd covered this already, but then I looked in, but we haven't.
18:51 And I looked into it and it's, and I obviously haven't played with it yet, but okay.
18:56 So test book is very cool.
18:58 Test book.
18:59 The idea is to test your Jupyter notebooks.
19:02 I think we've covered a couple things, ways to do that, but this is kind of a neat perspective.
19:07 So the perspective of this is you've got a notebook with maybe, let's say, functions in it, and you want to check those.
19:16 You want to make sure that you want to write tests against those functions.
19:19 Instead of putting the tests in your notebook, put them in like just a test file and run it with pytest or UnitTest or something.
19:28 And so to do that, though, like let's say I want to run a function foo and I want to do it from another file.
19:38 I've got to get that definition of foo into my test code.
19:41 And so what test book does is it has a decorator that you can either put it on your test or a fixture that goes ahead and runs the, one of the things you can do is run your notebook before the test runs.
19:55 And then you can pull out the definitions.
19:57 Oh yeah, this is really cool.
19:57 So you have a decorator, which has a path to the IPYNB file and execute equals true.
20:03 And by the time it gets to your code, it's already going to run that, that things defined like a function or variables defined within the notebook will just be accessible through the input parameter there.
20:13 Yep.
20:14 And the test gets a fix.
20:16 You can have a fixture to be able to grab values, references.
20:20 So the example we're showing right now shows pulling a function in, but I imagine you can pull in really anything, any name that exists within the notebook to be able to test it.
20:32 some of the neat things that it includes right off the bat is it's nice that it doesn't, it isn't just by test.
20:39 You can use it with unit test, apparently also with nose, but don't do that.
20:42 one of the ways things you can do also is in the, the original example of decorating a test, it's going to run that notebook for every, every test it's decorated.
20:53 You might not want that.
20:55 You might.
20:56 but if you want to run it all just once, you can put it in a fixture and then return the fixture.
21:01 That's a cool thing.
21:03 one reason why you might want to run it multiple times is if, if there are interactions between the different parts and you want to completely isolate those tests.
21:12 Another thing that's built into it is patching.
21:14 So you don't have to import mock.
21:16 You can patch different parts of your, your Python code, your Python notebook, your notebook code, with, like, like mock.
21:25 you can patch it right through this.
21:27 So that's pretty neat.
21:28 Yeah, that's pretty neat.
21:29 I like it.
21:30 Al, what do you think?
21:30 Nice.
21:31 Yeah.
21:31 I haven't had a lot of experience with Jupyter notebooks, but it's, it's sort of becoming the main way that a lot of people are being introduced to Python, especially if they're coming from, the sciences or academia.
21:42 Yep.
21:42 Yeah.
21:42 And so getting like sort of a lot of, informally trained software engineers, up to speed with, with like unit testing and other practices like that.
21:51 It's definitely something I can get behind.
21:53 Yeah, that's cool.
21:54 And the, getting the, the ability to call those pieces or interact with those pieces outside the notebook is quite tricky.
22:00 So this is a neat way to do it.
22:02 I mean, we've got paper mail, but I'm not sure exactly how that folds into testing and stuff like that.
22:06 Right.
22:07 Right.
22:07 Actually.
22:08 Yeah.
22:08 Yeah.
22:09 I don't think so.
22:09 I think it's more like inputs and outputs as a whole notebook.
22:13 Not like, let me get ahold of the function in the cell seven and try to call that.
22:17 Yeah.
22:19 Also, the target audience is different.
22:21 So the, the, the target audience for your notebook itself is different than you trying to test your code.
22:27 So, keeping the test code out of the notebook, I think is a nice thing to, to keep it clean.
22:34 Yeah, I totally agree.
22:35 taking a step back real quick.
22:37 Neil also asks, are the small programs in your book, Al, compatible with MicroPython or CircuitPython?
22:43 Probably not.
22:45 I don't know.
22:47 I haven't taken too much of a look at MicroPython.
22:51 but I do try to keep, all the source code as simple as possible and not really rely
22:58 on like the file system or making network connections.
23:00 Mostly it's just standard IO, input output streams for, for text.
23:06 So, you know, if, if it can run print and input, then likely it can, run these programs.
23:12 Yeah.
23:12 Maybe you just have to make the little lights blink and some sort of Morse code.
23:16 Yeah.
23:16 Perfect.
23:17 Nice.
23:18 All right.
23:19 Something that is a little bit mysterious to a lot of folks, I think partly because it's
23:24 somewhat discouraged, but not always is from package import star, right?
23:30 Well, sometimes discouraged because you probably shouldn't.
23:33 There probably are situations where you want to do that.
23:36 Like if I've got three sub modules and I want to take the elements in them and then like
23:40 drop them into the top level dunder init for a package so that I can just say package name
23:45 dot items, but not organize them into one giant file.
23:48 For example, that might be reasonable.
23:50 The way that you control that is you work on the dunder all definition at the top of your package,
23:58 right?
23:58 And in there you can say, oh, here are the names of the things that I would like to export.
24:02 If you import star rather than everything, give them these, right?
24:06 Maybe you define some weird thing called Django and it's not meant to override Django or something
24:13 like that, right?
24:13 You want to leave that out.
24:15 So how do you manage that?
24:17 Well, there's this project over on GitHub called auto all, auto dash all.
24:23 And the idea is it somewhat automagically manages the dunder all variable for Python modules.
24:29 So there's a couple of ways in which you can do it.
24:32 You can exclude certain things.
24:36 You can clearly differentiate what's meant to be treated as an external item and what's meant
24:41 to be treated as an internal item.
24:43 You don't have to worry about continuing to update the dunder all and so on.
24:48 So you just pip install it.
24:49 And then the most, it seems like the recommended way, I guess, is you would fall somewhere in
24:56 your script at the top level, like at the function or class level, right?
25:00 No tab space, no spaces, no indentation.
25:03 You say start all, then you write a bunch of code functions and so on.
25:07 And then you say-
25:08 You mean auto all dot start all?
25:10 Yeah, yeah, yeah.
25:10 If you, if you, yeah, if you, exactly.
25:13 If you import it from there, right?
25:14 I guess you could even import star from there.
25:16 But you say start all, and then you write a bunch of code and then you say end all.
25:19 And then basically between those two markers, those are the things that go into your dunder all
25:25 variable.
25:25 There's something about classes.
25:27 It will not work for classes or variables as well.
25:31 Sorry, take it back.
25:32 It will with the start all, end all.
25:34 But there's also another way that only works on various functions.
25:37 And that is to put a decorator onto the function, which I think, I like this a lot, but the fact
25:42 that it doesn't work with classes, it sounds like that should actually be a PR folks, a little
25:47 thing that, an extra one, like public class or I don't know, whatever.
25:51 But that seems pretty cool.
25:51 So you just say at public on a function, and then that will add it to the dunder all.
25:57 So if you want to export three functions from your module, you just put at public on those.
26:00 And that way, when you're looking at it, it's like really clear.
26:02 These are the public functions and the rest aren't.
26:04 I mean, you could still from module import name, but not through the all, right?
26:09 Yeah.
26:10 Okay.
26:10 Anyway, it looks pretty cool, right?
26:12 Yeah, that is actually a really nice way to just have this automatically taken care of.
26:18 I mean, ideally, you're not really doing the from module import star all too often, or
26:24 rather, ideally, I'm the only person in the entire world that should be allowed to do that.
26:29 And everybody else will have to do it the proper way.
26:32 It's a bad idea.
26:32 Don't do it.
26:33 But it's very handy.
26:34 No.
26:34 Yeah, this is really handy.
26:36 Yeah.
26:36 Dean out there in the live stream says this should work with a context manager.
26:39 Yeah, it probably should.
26:40 I think the challenge would be then you'd have like all of your implementation indented, but
26:45 still pretty cool.
26:46 Yeah.
26:47 So actually, I'm reminded of one of the places I do do import all or import star is in dunder
26:56 init files for packages.
26:57 Yes, exactly.
26:58 In those cases, I often do pull in.
27:01 I've got a couple modules that have my interface and I pull everything in from there.
27:06 So those are cases where that is something that happens.
27:11 And then you're faced with, well, what if I want to put another function that isn't part
27:15 of my public interface?
27:16 Then you have to jump through hoops.
27:17 So I'd probably use it in those cases.
27:19 Yeah.
27:20 I don't think it's broadly applicable, but for the people who are really trying to carefully
27:24 manage their dunder all, it seems nice.
27:26 Straightforward.
27:27 Simple.
27:27 Yeah.
27:28 Yeah.
27:28 Yep.
27:29 All right.
27:29 Al, I think you got the last one, right?
27:32 Yeah.
27:33 So I am working on another book.
27:36 I have a really bad book writing problem.
27:39 I keep thinking that this will be the last one and then I have ideas for 10 or 20 more.
27:45 But the book that I'm currently working on and I'm down to the drafts of the last two chapters
27:50 is a book on recursion.
27:52 So this is currently my untitled recursion book.
27:55 But yeah, I gave a talk at North Bay Python, I believe in 2018 or 2019, that was an introduction
28:03 to recursion.
28:04 And recursion is one of those things where a lot of people find it very intimidating or
28:10 even just outright magical.
28:12 And it's this thing that seems to be like only for advanced programmers or something like
28:17 that.
28:18 But I started taking a look at it.
28:20 Or beginner programmers who make a mistake.
28:21 Oh, yeah.
28:22 Right.
28:23 Exactly.
28:24 Accidentally.
28:24 Just keep calling it.
28:25 Yeah.
28:26 Just for some general background.
28:27 Recursion is when you have a function that calls itself.
28:31 And this is it sounds like it won't work.
28:35 And oftentimes it won't.
28:36 You'll get a sort of an infinite loop of recursive function calls and then it crashes your program.
28:41 But there are recursive algorithms where this is a really handy technique and allows you to
28:48 do really sophisticated things in not that much code.
28:50 However, a lot of people find it really confusing.
28:53 But more than anything, I found that it's just poorly taught.
28:57 Most people will probably learn this from a computer science professor or they'll be studying
29:02 it as a way to prepare for job interviews for the coding section.
29:07 You know, there's a lot of times where people will be writing out an algorithm on a whiteboard
29:11 and their interviewer will say like, OK, and now can you do the recursive version of this
29:15 algorithm as a quick gotcha?
29:18 But yeah, there's the short of it is I realized that a lot of times people don't really teach the concept of the call stack.
29:26 And without explicitly knowing about what a call stack is and how it works, a lot of what recursion does kind of just seems magical because you're missing this huge piece.
29:35 And I found out so many other things about this.
29:37 And so I thought, hey, I could write a quick little tutorial on recursive functions and make a talk.
29:44 And then that just kind of ballooned into a giant book now.
29:48 That's how I end up with courses.
29:49 I'm like, oh, that'd be a neat little thing to play around with.
29:52 Why have I spent the last month doing this?
29:54 Yes.
29:55 So I'm hoping to have this book probably done either at the end of this year or early next year in 2022.
30:03 But yeah, so a book that just covers recursive algorithms and and why people find recursion to be so intimidating and how it really isn't.
30:13 And even how oftentimes it's actually not the best technique to use.
30:19 You just want to write straightforward, simple code.
30:22 But if you really want to show off how smart you are and annoy your coworkers that way, recursion is also really great for that.
30:29 What I like about it is if you have hierarchical data, it matches that really cleanly.
30:34 Yes.
30:35 You want to traverse a tree, but in like a real simple way.
30:38 Or you want to work with an algorithm that is like iterative in the sense like the previous step kind of naturally the answer that leads to the next one.
30:45 Those types of things.
30:46 It's like a super elegant answer.
30:48 Yeah.
30:49 I found that recursive algorithms are really great when your problem has a tree like structure and also involves backtracking.
30:58 Otherwise, there's probably you probably just need a loop or some iterative way of solving it.
31:04 You can also come up with a cool joke like the one we had on episode 236.
31:08 There are so many recursive jokes.
31:12 I actually opened up my talk at North Bay Python with just like, OK, we just got to get that out of our systems.
31:18 Do the whole, you know, in order to learn about recursion, you first have to learn about recursion.
31:23 These jokes that we've heard like millions of times.
31:26 Yeah.
31:27 People can check out the little cartoon graphic thing on episode 236.
31:31 Yeah.
31:32 I was going to ask you if you're right.
31:33 You got anything you want to just throw out there at the end?
31:35 No, I've just been working a lot.
31:39 I was just one question.
31:41 I was just going to think that maybe Al's book was about how to write a book about recursion.
31:45 The making of is something that I've also been thinking of.
31:49 I feel like a book on meta classes and meta programming might be very relevant.
31:54 All right.
31:56 I got a couple of things to cover for my extras.
31:58 OK.
31:59 First, I had talked about Oh My Posh.
32:01 Oh My Posh, which I think is a really cool like Oh My Z shell type of thing.
32:07 But for PowerShell and if you use the new Windows terminal and you get the new PowerShell 7 and set that to be the default, then you get these really beautiful, nice prompts and autocomplete and all those kinds of things.
32:20 So those are really neat.
32:21 People can check that out for all the Posh shell stuff.
32:25 But someone was asking for something that would do a thing that is really cool.
32:30 Like what if what if when I and oh, by the way, because we gave it a shout out, right?
32:36 I was dreaming of something that would automatically activate virtual environments when I seeded into a structure that contained in the tree somewhere a virtual environment, which is cool.
32:48 So they dug around and said, I found this thing called Posh dash Dure Envy, which does that.
32:54 So as you change into the directory, it will automatically activate virtual environments.
33:01 Nice.
33:02 Nice.
33:02 Yeah.
33:03 So that's pretty neat.
33:04 So people can check that out.
33:06 It's a sort of follow up.
33:07 Another thing.
33:08 One of our listeners, Einstein, Vincent, I believe is the one who sent it over.
33:13 Thank you for that.
33:14 Just said, hey, quick shout out.
33:15 Your show has been super helpful to us.
33:17 It's been inspiring a bunch of us scientists.
33:19 We're here in Iceland and I believe also at Harvard, if I recall correctly.
33:23 And they now publish an article using Python, a scalable method of determining physiological endotypes for basically a sleep apnea study of trying to turn this into more of a continuum rather than yes or no.
33:38 You have yes or no.
33:39 You yes do or don't have sleep apnea.
33:41 So really cool just to see listeners listening to the show, using some of the packages and doing cool stuff that help people.
33:46 Yes.
33:47 one more follow up to three more follow ups, actually.
33:51 But next one really quickly.
33:52 I've been having such a challenge with email for two years and I have finally, I think solved it.
34:00 The beast.
34:01 I believe I have had hundreds of emails from years ago that needed action.
34:07 And finally, I've gotten back to almost everybody down to just a handful of emails and I'll have them all done.
34:12 But anyway, I want to recommend two email clients.
34:14 One for the Mac is Newton.
34:15 Pretty cool.
34:16 And then I'm going to give superhuman a try, but it takes a while to get set up on that.
34:21 If you're out there struggling with email, check those out.
34:23 And so we've heard about cloud computing.
34:26 That's where you might run your program in the cloud.
34:28 You've heard about virtual environment or sorry, virtual machines.
34:31 That's where you might fire up a computer that runs in a container or a virtual hypervisor.
34:36 And then you can interact with that in like its own little way.
34:39 But Microsoft, apparently I was just reading like 15 minutes before we started.
34:42 I thought I'd throw this in there.
34:43 They just reveal not just Windows 11, but Windows 365, which is basically you buy Windows and the thing hosted in the cloud.
34:52 So you just like in a web browser to it or something.
34:54 And then you have a computer with all your files that's instantly on.
34:57 So I don't know.
34:58 I thought that was kind of interesting.
34:59 Throw that out there.
35:00 It's like Office 365, except the entire operating system.
35:03 The entire computer with all your files like saved there.
35:06 Yeah, exactly.
35:06 Probably expensive.
35:07 I have no idea.
35:08 Last thing.
35:09 We talked about Flock No, right?
35:12 We talked about Flock and the vanishing of third-party cookies and the stuff that Google is trying to do.
35:18 And then remember that Brian, you pointed out they received significant feedback.
35:21 That was not totally positive for them.
35:23 Yeah.
35:24 So, you know, parallel to that, I think, is really interesting is that Apple also had their do not track thing that they put on their phone, which is fine.
35:33 But I think it just needs to be way more than that.
35:35 But yeah, so they have that.
35:36 And would you be surprised that only 25% of the people said, yes, please track me?
35:40 I'm actually surprised that 25% of the people said yes.
35:43 Like, if it's over 5%, it's blowing my mind, right?
35:47 Like, yeah.
35:47 Who's saying yes?
35:50 Exactly.
35:51 So here's an article.
35:52 Facebook and its advertisers are panicking as the majority of iPhone users opt out of tracking.
35:58 And I saw that 20% of ad spend has now moved away from iPhone and towards Android because Android doesn't, you know, they're happy to track you.
36:05 That's Google.
36:06 Yeah.
36:07 But also just I think it's very meta and funny.
36:09 So I have my VPN that has a ad blocker plus cyber, like basically virus malware detector at the network layer.
36:16 Notice there's a big gap in me showing you this article up here.
36:19 That's as we're trying to show me the ad about the advertisers and my network.
36:24 My VPN is blocking it, which I just love it.
36:26 So anyway, those are all the things that I had to share there.
36:30 Al, you got anything else you want to throw out there for everyone?
36:32 Yeah.
36:33 Outside of the books, I'm also working on my open source project called PyAutoGUI.
36:39 This is a GUI automation module for Python where it's a module that lets your Python scripts control the mouse and keyboard.
36:46 So if you have some software that you want to automatically click and type things into, you can write a script using PyAutoGUI to do that.
36:53 It works on Python 2 and 3 and also on Windows, macOS and Linux.
36:58 I feel like I've been neglecting this project for the longest time, but more and more people are using it.
37:04 So I really want to start adding more and more features to bring it up to speed with a lot of other GUI automation libraries that are out there.
37:12 So if anybody is interested in contributing, I have the GitHub link.
37:16 And you can also just Google for PyAutoGUI to find more information about that.
37:22 That's cool. I found out by Googling with DuckDuckGo.
37:25 Yes.
37:26 I still have a problem saying Google as the verb.
37:30 No, I do too.
37:32 I finally got over using guys as a general neutral pronoun, but now I still have problems saying Google all the time.
37:38 Yeah.
37:38 It's all hard.
37:40 By the way, notice over here.
37:42 I still have trouble not telling people to MapQuest something.
37:45 Yeah, I know.
37:47 It's good, except those little arrows to move each around on the map of little bars on each side.
37:52 It's so clunky.
37:53 And you got to print the thing out for like five pages and follow the pictures.
37:57 No, but so one thing I do want to give a quick shout out to the guys that read the docs, Eric and crew over there.
38:02 Like they have an ad right here and it says sponsored ads serve ethically.
38:07 You know what that's based on?
38:08 Not tracking and retargeting.
38:10 That's just, hey, there's something to do with this Python project.
38:13 So this ad has to do with the context of what is here.
38:16 It's relevant to the content I'm already looking at.
38:19 Good old fashioned.
38:20 That's astounding.
38:22 Just like magazines and newspapers and stuff like that.
38:24 And it's not about finding hot singles in my local area.
38:27 That's great.
38:30 Exactly.
38:31 All right.
38:32 Cool.
38:33 Yeah.
38:34 Cool.
38:34 Thanks.
38:34 Thanks, Al, for joining us today.
38:36 And Brian, as always.
38:38 Thanks for having me.
38:39 Yeah, you bet.
38:40 Thanks, everyone, for listening.
38:41 Thanks for listening to Python Bytes.
38:43 Follow the show on Twitter via at Python Bytes.
38:46 That's Python Bytes as in B-Y-T-E-S.
38:49 Get the full show notes over at Pythonbytes.fm.
38:52 If you have a news item we should cover, just visit Pythonbytes.fm and click submit in the
38:56 nav bar.
38:57 We're always on the lookout for sharing something cool.
38:59 If you want to join us for the live recording, just visit the website and click live stream
39:03 to get notified of when our next episode goes live.
39:06 That's usually happening at noon Pacific on Wednesdays over at YouTube.
39:11 On behalf of myself and Brian Okken, this is Michael Kennedy.
39:14 Thank you for listening and sharing this podcast with your friends and colleagues.