Transcript #116: So you want Python in a 3D graphics engine?
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:05 This is episode 116 recorded January 29th, 2019.
00:10 I'm Michael Kennedy.
00:11 And I'm Brian Okken.
00:11 And this episode is brought to you by DigitalOcean.
00:14 Check them out at pythonbytes.fm/digitalocean.
00:17 For now, I would like to get out there and explore a dictionary.
00:22 What do we got here, Brian?
00:23 This is totally cool.
00:26 I don't even know what to call this.
00:28 I've got a link, it's called Inside Python Dict, an Explorable Explanation.
00:33 But it's really like a four-page different tutorial.
00:36 It starts with lists and searching efficiently in a list, and then it kind of builds up to dict, so it has like a description of what hash tables are, why are they called hash tables, and then creates a Python-like, almost Python dictionary structure.
00:54 It's a deep dive.
00:56 Then at the end, it does actually show you how Python dictionaries really work.
01:01 It's a pretty deep dive, but what I really want to highlight is the interactiveness of this.
01:07 If you go take a look at this, it shows a lot of the examples in playable code.
01:14 The code's like auto-playing with a little, it looks like a debugger where it walks you through different lines and then shows you the output.
01:23 And it's this very visual way to learn.
01:26 And it's pretty darn cool.
01:28 And I don't even know how they're doing this, but you can figure it out if you want to, 'cause all of the code for this website is up on GitHub.
01:34 - This is a cool example, and you're right.
01:36 The little visual play to highlight the code, highlight the visual data structures animation is really great, I think.
01:43 - Yeah, it's a neat option.
01:45 And then occasionally, some of the code has like fill in the blank stuff, where you can type in stuff and change what the code does on the back end.
01:53 And it's just, I don't even know how this is doing it, but it's fun.
01:57 And actually really getting a handle on how dictionaries work in Python is one of the superpowers.
02:05 To get really good at Python, you kind of have to really grok dictionaries.
02:09 So this is a good thing.
02:11 - Yeah, they're certainly used more than regular, let's say everyday programming languages like C, C++, C#, Java.
02:19 They have dictionaries or hash tables, but they are not built on top of them, right?
02:24 Like the variables you look up come out of the locals dictionary, right?
02:28 Your classes and their fields and values and attributes are based on dictionaries.
02:32 And yeah, understanding them is super important.
02:34 This is a cool example.
02:35 I like it.
02:36 Yeah.
02:36 So neither of us are super big gamers, but there's a lot of people out there who are.
02:41 And then there's also a lot of people building visualizations or 3d interactions.
02:47 And Python itself is also used a lot in creating pipelines for creating games and movies and stuff like that.
02:54 So I kind of have a theme through this whole episode that I put together.
02:58 I ran across some stuff kind of all at once.
03:01 And so the first one I want to talk about is the Unreal 4 engine, which is one of the big game engines, you know, built on C++, things like that.
03:09 So as like Fortnite, save the world, Gears of War 4, Marvel versus Capcom, System shock, not the old one, which is an awesome game from the nineties, but the new one that's being remade, all these are being done on unreal engine four and the news is you can now use a plugin to embed Python three.
03:28 Entirely inside of the unreal engine, both for controlling editing, like automating a scripting, say loading a bunch of stuff and auto-generating characters or stuff like that.
03:39 And also runtime, like even characters in the games.
03:41 That's neat.
03:42 That's cool.
03:43 Right?
03:43 So yeah, so basically this is like a meta plugin.
03:46 Like you take this plugin, you stick it in an unreal, and then you can create Python plugins to do stuff and even write automated tests against like the AI of your game and stuff like that.
03:56 Oh, wow.
03:56 Yeah.
03:57 It's pretty interesting.
03:58 And the, the GitHub repo is super detailed in like walkthroughs and steps.
04:03 So there's an example usage on how to create this character from a mesh and from textures and stuff in Python.
04:11 in the editor and there's also one about how to create gameplay elements, you know, that run around in a game.
04:16 So it looks really cool if anyone needs to do 3d interactive stuff and they want to use Unreal four engine or even plug into a game that exists like some, there's a whole bunch more than the ones I listed here.
04:28 This is a cool option here.
04:30 Yeah.
04:30 Nice.
04:31 Cool.
04:31 Yeah.
04:32 So this next one you got for us is on context lab.
04:35 I'm a big fan of context managers in the West statement.
04:37 Tell us what you found.
04:38 I was actually slow to come to context managers, but they definitely, once you get your head around them, they're really handy.
04:45 And I saw this reference and I didn't know existed.
04:49 There's a lot of functions that just print stuff, like they print stuff to standard out or to standard error.
04:54 And I am used to testing that.
04:57 I know how to test that.
04:59 With pytest, there's the capsys fixture that you can use that to capture the output of something and check what it is and read it, whatever.
05:08 But there's a lot of times where you might be using something that prints to standard out and you don't want it to, or you want to be able to get that output programmatically.
05:18 And ContextLib has a redirect standard out function that you just give it a new target and then using the with statement, run whatever code you're gonna run and you can capture the output.
05:31 And didn't know that was there and it's very cool.
05:33 I'm going to drop a little tiny code snippet in the show notes to show people how to use it.
05:39 - Yeah, and it'd be great for testing or something like that without trying to do too much.
05:44 What's cool that I like about this is, 'cause it's a WHIS statement, a little bit of code is being redirected, then it goes back to normal.
05:51 It's not like you're permanently changing what it is.
05:54 It's just maybe during a test or during one function call or something.
05:58 - I didn't put this in the show notes, but in the link to the ContextLib documentation, The output I showed in our example, just capturing it with string IO.
06:09 But you can pass it in like a file.
06:10 So if you've got part of your system that usually just prints to send it out, you can redirect all that to a file if you want to save it somewhere or something.
06:18 - Yeah, nice.
06:19 And there's a standard error addition as well, right?
06:20 - Yep. - Sweet.
06:21 You know, I love this pattern.
06:22 I've done stuff like this with colored output.
06:25 So use something like Colorama and say, for this output, I would like it to go to green, But then I wanted to go back to whatever it was before.
06:33 So a really nice way to do that as well is to put it into one of these, create a little context manager, throw it in there, and just the stuff that interacts with a console or terminal in the with block is great.
06:44 That's pretty cool.
06:45 I like this better.
06:46 Very nice.
06:47 Before we move on to the next one, let me tell you about DigitalOcean.
06:50 Of course, a lot of our hardware is running on DigitalOcean.
06:53 They're super, super nice.
06:54 One thing I don't know much about, Brian, I don't know how you're doing, is Kubernetes.
06:58 Have you done a lot of Kubernetes?
06:59 - I have not.
07:00 I have not either, but it definitely seems like one of the most widely adopted ways to use Docker containers and orchestrate them and really take more than one Docker container and make it work as a whole, do live zero downtime upgrades, things like that.
07:14 So you should check out DigitalOcean's Kubernetes, D-O-K-8 service, which is a managed Kubernetes service.
07:22 It's out officially now.
07:23 It's been around in beta and alpha for a while.
07:25 So you can deploy faster, get your Kubernetes clusters in seconds, provision and access it in a few minutes, easily scale, persistent storage based on incoming traffic with block storage and load balancers and whatnot.
07:37 And it costs 2.4 times less or better performance per price compared to the other providers.
07:43 So on top of that, if you go to pythonbytes.fm/digitalocean as a new user, you get $100 credit to Kubernetes, all the things.
07:51 So it sounds like a lot of fun and definitely check it out.
07:54 It supports the show.
07:56 So to continue on with my theme, It's all about the 3D and the Python.
08:01 So the next one I wanna cover is something called Panda 3D.
08:05 And now it may seem very similarly named to Pandas, but it has nothing to do with that.
08:10 It's just an open source, completely free to use game engine for real time 3D games, visualization, simulation, simulations, experiments, all that kind of stuff.
08:20 This one comes from Kolia Lubitz.
08:23 Hopefully that was close enough.
08:24 Thank you, Kolia, for sending that in.
08:26 That's great.
08:27 One of the things I thought was cool, I don't think everyone's gonna be building a game, but I think a lot of people out there are doing science and experiments and visualizations and stuff like that.
08:36 And I think this is a great little 3D engine for simulations that just happen to be in 3D and you can do them in Python.
08:42 - Oh, that's cool.
08:43 - Yeah, isn't that nice?
08:44 So this is basically a C++ 3D engine that has a bunch of library plugins and stuff that make it a lot easier to work with.
08:53 So it runs on all the platforms.
08:56 It has very little overhead because you basically get your meshes, you load them into the system, and then you just sort of poke at them and control them from Python, but they run on your GPU in C++.
09:08 So really good performance as well.
09:10 - Oh, nice.
09:11 - Yeah, so some of the features, platform portability, it runs on Mac, Linux, and Windows, maybe Raspberry Pi.
09:16 I can't remember where else, possibly other places, but the main places, it has a lot of tools for handling assets.
09:23 I don't know if you've ever done anything with 3D, but it's these library files and this Adobe file format for that other thing, and there's just all that kind of stuff.
09:34 So there's a lot of tools for handling these assets, which is pretty awesome.
09:38 So you can automate either your pipeline or even the code.
09:42 It also has library bindings, which is cool.
09:45 So you can do things like plug in the Bullet Physics Engine or the As-a-Map Loader or OpenAL or all these different things that, Just because you have 3D doesn't mean you have physics or interaction and stuff like that, right?
09:58 - Yeah. - Pretty cool.
09:59 And then finally, it comes with this thing called PStance for Panda 3D profiling.
10:04 So you can actually get a visual representation of exactly where your program is spending its time, like this frame or this mesh or whatever.
10:12 It takes that amount of time to run.
10:14 So you get super detailed runtime, profiling, and performance analysis.
10:18 So not bad for a completely free Python-enabled thing.
10:22 - Yeah, and it's completely free.
10:23 You can even use it for commercial use if you want.
10:25 - Yeah, exactly.
10:26 And I don't think Unreal 4, for example, is.
10:28 So this is a nice one.
10:30 - Nice.
10:31 - Yep, what's the next thing you got?
10:32 - I have an interesting article, and I should have written down, it's from Dustin Ingram, called "Why PyPI Doesn't Know Your Project's Dependencies." And I guess it's something I never really thought about before, but if you go look on packages on PyPI, it would be kind of cool if you could see all the dependencies of a particular package.
10:53 - Yeah, you can do it on GitHub as a whole project, but you can't do it as like a single, you can't go, this package I'm gonna get has, exactly, that's nice, that would be nice.
11:02 - He's trying to answer, he says he gets a lot of questions like how can I produce a dependency graph for Python packages?
11:08 Man, why doesn't PyPI show that the project dependencies right out on the page, that would be neat.
11:15 And also just how can I get all the dependencies without downloading it first?
11:20 And the answer is you can't, which is interesting.
11:23 And the reason is because of setup tools, then setup.py is dynamic.
11:29 It's code, it runs.
11:30 And it gives an example, which is sort of funny.
11:33 It gives an example of building a setup.py package that does a dependency with random choice.
11:41 So randomly pulls in different packages.
11:43 - Fun, just to make a point.
11:45 - Yeah, so that would be evil, but it could be done, and I'm hoping that a listener will do this and push it up just for the heck of it.
11:52 But there's some real reasons to do that.
11:55 And a lot of them have to do with like different packages being available on Windows versus Linux versus Mac or whatever.
12:03 So operating system dependencies are something that often makes you have to pull one in versus another.
12:09 Also, different versions of Python.
12:11 So if you're using Python different, if you wanna use data classes and you're using an older Python, you need to actually depend on data classes, for instance.
12:20 So this is an interesting article that talks about that, but also points out why wheels are awesome.
12:26 So wheels are not something that are dynamic, they are more predictable.
12:33 So this is, I think, also a little bit of a plug for wheels.
12:37 And I wanted to highlight that wheels, they have dependencies in them also, but they're not as dynamic.
12:43 So there'll be a different wheel up there for different operating systems.
12:47 And while I was poking around on here, I also wanted to go on a little bit of a tangent.
12:53 There's a website called pythonwheels.com that I'll just drop a link in here too, and it talks about some of the advantages of wheels.
13:01 - It's nice, installs faster, doesn't run set up PUI.
13:05 Yeah, doesn't require a compiler.
13:07 So basically, kind of a binary version instead of a source version, which is cool.
13:12 for some packages that have wheels up there, it is kind of cool if you can put up, if you've got hard operating system dependencies, then have some sort of build step that puts those up for the different operating systems.
13:24 - Yeah, cool.
13:25 I like it, and it's a totally reasonable question.
13:27 Like, I'm considering installing this thing.
13:30 What does it use, right?
13:32 That's a little, that should be obvious, and I'm not sure it is.
13:34 - And one of the things I also, I don't know why people are, if you really want to know on my operating system, what do I need?
13:41 - pip includes a command called download.
13:43 So you can say pip download something and point it to a directory and it'll download something and all of the dependencies that are valid for your operating system.
13:54 So if you're really curious, that's one way to do it.
13:57 - Very, very cool.
13:58 All right, for the last one, I want to talk about building games and other stuff, other stuff with Python.
14:05 Now this one is different than the other.
14:06 The first two, there's about 3D engines, one, a big commercial one and one, a free open source one that you can plug in and control and automate and work with, with Python.
14:14 But what this is actually, this one makes me super excited.
14:17 It makes me want to go along with it.
14:19 It's a, at least six part series.
14:22 On PI game.
14:23 And they're really quite detailed and in-depth and interactive.
14:27 So I'll just give you a sense.
14:28 It starts out with building a simple dice game, then building a game framework.
14:33 So you can build on top of it, adding players, moving your characters around, having heroes and villains that fight.
14:40 And then the last one, at least at the time of the recording is putting platforms in a Python game with Pygame.
14:47 And what they mean by that is, you know, think of Mario brothers or joust or something like one of these old 2d side scroller games.
14:56 Like how do you create a game with that?
14:58 And it's pretty elaborate and pretty nice.
14:59 Oh, that's cool.
15:00 Yeah.
15:00 It's like a, basically the six part series.
15:02 So if you wanted to kind of get your Python better.
15:04 Or you wanted to learn Pygame either of those, this would be a really cool set of series to go through because I'm going to come up with like a 3D side scroller, sorry, 2D side scroller game at the end and that that seems pretty awesome.
15:15 Man, I haven't thought about Joust in a long time. I missed that game. That was cool.
15:19 I know. I can't even remember the sounds but yeah I remember it for sure.
15:23 Even the arcade there, that was fun. Yeah that one in Dungeon, that Dungeon game that was sort of just a video more or less. Those were fun times. Now one other thing that I want to throw in here like so this is the series and that was That's kind of what I want to talk about.
15:37 I'm linking to all the pieces.
15:38 But something I ran across recently as well that I thought was pretty cool.
15:42 I haven't gotten it.
15:43 I haven't played with it yet, but it gave me the same feeling of like, "Oh, this looks so cool," is this thing called Mission Python, a code space adventure game.
15:51 So similarly, it's like a whole learn Python and learn Pygame by building like a space adventure game with Pygame.
15:58 And it just looks so fun.
15:59 I just, I want to do it, but haven't done it yet.
16:01 I haven't ordered the book.
16:02 Yeah, it does look fun.
16:03 Neat.
16:04 Yeah.
16:05 If you're interested in learning Pygame or you want to use Pygame for some kind of simulation type thing, either of these would be real helpful.
16:12 Yeah. Sorry. I'm already giggling about the joke.
16:17 Yeah, it's coming. So, those are our main items. You got anything extra to share with folks before we unleash an amazing joke on them?
16:28 No, nothing extra this week. How about you?
16:31 - How about you?
16:32 - Not really, but I do wanna say I'm looking forward to being at PyCascades with you and everyone else up in Seattle in the February.
16:38 So if there's still tickets available by the time this goes out and people wanna make it there, then definitely check it out.
16:44 It was a fun conference last year.
16:46 - Definitely.
16:46 - Absolutely.
16:47 All right, I guess we got our friend, Dan Bader, to thank for this, don't we?
16:50 - I guess, I think, I'm not sure.
16:53 Somebody at RealPython.
16:54 - Yeah, somebody at RealPython.
16:55 All right, hit us with a joke.
16:56 This comes from the RealPython Twitter and I linked to the joke.
16:59 It's got a little graphic to it, but you can do it without.
17:01 - Yeah, so why do pythons live on land?
17:03 - I don't know, they're snakes, I don't know why.
17:05 - 'Cause they're above sea level.
17:07 (laughing)
17:09 - The letter C, capital dash level, of course.
17:12 - Yes, 'cause python's a higher level language, you know, it gets worse as you explain it more.
17:17 - That's right, so yeah, 'cause you don't compile it, no.
17:21 Yeah, it's bad.
17:22 It's a good joke, though, and very, very funny.
17:26 Thanks for sharing.
17:27 - Yeah, definitely, so thank you.
17:29 - Yeah, thanks for doing the episode as well, and goodbye, everyone.
17:31 Thank you for listening to Python Bytes. Follow the show on Twitter via @pythonbytes.
17:35 That's Python Bytes as in B-Y-T-E-S. And get the full show notes at pythonbytes.fm.
17:41 If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
17:46 We're always on the lookout for sharing something cool. On behalf of myself and Brian Okken, this is Michael Kennedy.
17:52 Thank you for listening and sharing this podcast with your friends and colleagues.