« Return to show page
Transcript for Episode #116:
So you want Python in a 3D graphics engine?
0:00 KENNEDY: Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is Episode 116, recorded January 29th, 2019. I'm Michael Kennedy.
0:11 OKKEN: And I'm Brian Okken.
0:12 KENNEDY: And this episode is brought to you by Digital Ocean. Check them out at pythonbytes.fm/digitalocean. For now, I would like to get out there and explore a dictionary. What have we got here, Brian?
0:24 OKKEN: This is totally cool. I don't even know what to call this. I've got a link, it's called Inside Python Dict: An Explorable Explanation, but it's really like a four page different tutorial. It starts with lists, and searching efficiently in a list, and then it kind of builds up to dict, so it has a description of what hash tables are, why are they called hash tables, and then creates a Python-like, almost Python dictionary structure, and it's sort of a deep dive into, and then at the end, it does actually show you how Python dictionaries really work. It's a pretty deep dive, but what I really want to highlight is the interactiveness of this. So, if you go take a look at this, it shows a lot of the examples in playable code, so the code's auto-playing with a little, looks like a debugger, where it walks you through different lines and then shows you the output, and it's this very visual way to learn, and it's pretty darn cool. 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.
1:34 KENNEDY: This is a cool example, and you're right, the little visual play to highlight the code, highlight the visual data structures animation is really great, I think.
1:43 OKKEN: Yeah, it's a neat option. 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 in the backend, and it's just, I don't even know how this is doing it, but it's fun. And actually, really getting a handle on how dictionaries work in Python is one of the, like, the superpowers. To get really good at Python, you kind of have to really rock dictionaries, so this is a good thing.
2:11 KENNEDY: Yeah, they're certainly used more than regular, let's say everyday programming languages like C, C++, C#, Java, they have dictionaries or hash tables, but they are not built on top of them, right? Like, the variables you look up come out of the locals dictionary, right? Your classes, and their fields, and values, and attributes are based on dictionaries, and yeah, understanding them is super important. This is a cool example, I like it. So, neither of us are super big gamers, but there's a lot of people out there who are, and then there's also a lot of people building visualizations, or 3D interactions, and Python itself is also used a lot in creating pipelines for creating games, and movies, and stuff like that, so I kind of have a theme through this whole episode that I put together. I ran across some stuff kind of all at once, 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, so it has Fortnite, Save the World, Gears of War 4, Marvel vs. Capcom, Systemshock, not the old one, which is an awesome game from the 90s, but a new one that's being remade. All these are being done on Unreal Engine 4, and the news is, you can now use a plugin to embed Python 3 entirely inside 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, and also runtime, like even characters in the games.
3:41 OKKEN: Wow, that's neat.
3:42 KENNEDY: That's cool, right? So yeah, so basically, this is like a meta-plugin. Like, you take this plugin, you stick it into Unreal, and then you can create Python plugins to do stuff, and even write automated tests against the AI of your game and stuff like that.
3:55 OKKEN: Oh, wow!
3:56 KENNEDY: Yeah, it's pretty interesting. And the GitHub repo is super detailed, and like, walkthroughs, and steps, so there's an example usage on how to create this character from a mesh, and from textures and stuff in Python in the editor, and there's also one about how to create gameplay elements, you know, that run around in a game. So, it looks really cool. If anyone needs to do 3D interactive stuff and they want to use Unreal 4 engine, or even plug into a game that exists, like, there's a whole bunch more than the ones I listed here, this is a cool option here.
4:30 OKKEN: Yeah, nice.
4:31 KENNEDY: Cool, yeah. So, this next one you've got for us is on contextlib. I'm a big fan of context managers and the with statement, tell us what you found.
4:38 OKKEN: I was actually slow to come to context managers, but they definitely, once you get your head around them, they're really handy, and I saw this reference and I didn't know existed. There's a lot of functions that just print stuff, like they print stuff to standard out or to standard error, and I am used to testing that, I know how to test that 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. 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, and contextlib.redirect_stdout() function that you just give it a new target, and then, using the with statement, run whatever code you're going to run, and you can capture the output, and didn't know that was there, and it's very cool. I'm going to drop a little tiny code snippet in the show notes to show people how to use it.
5:39 KENNEDY: Yeah, that'd be great for testing something like that without trying to, like, do too much, right? What's cool that I like about this is, 'cause it's a with statement, a little bit of code is being redirected, then it goes back to normal, right? It's not like you're permanently changing what it is, it's just, maybe during a test or during one function call or something, right?
5:58 OKKEN: 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 StringIO, but you can pass it in, like, a file, so if you've got part of your system that usually just prints the standard out, you can redirect all that to a file if you want to save it somewhere.
6:17 KENNEDY: Yeah, nice, and there's a standard error edition as well, right?
6:20 OKKEN: Yep.
6:20 KENNEDY: Sweet. You know, I love this pattern I've done stuff like this with colored output, so use something like Colorama and say, for this output, I would like it to go to green, but then I want it to go back to whatever it was before, 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, like, that interacts with the console or terminal in the with block is great, right? That's pretty cool. I like this pattern, very nice. Before we move onto the next one, let me tell you about Digital Ocean. Of course, a lot of our hardware is running on Digital Ocean. They're super, super nice. One thing I don't know much about, Brian, I don't know how you're doing, is Kubernetes. Have you done a lot of Kubernetes?
6:59 OKKEN: I have not.
7:00 KENNEDY: 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, zero down time upgrades things like that. So you should check out Digital Ocean's Kubernetes DOK8 service, which is a managed Kubernetes service it's out officially now, it's been around in beta and alpha for a while, so you deploy faster, get your Kubernetes cluster 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 what not. And it costs 2.4 times less or better performance per price compared to the other providers so on top of that if you go to pythonbytes.fm/digitalocean as a new user you get a $100 credit to Kubernetes all the things. So it sounds like a lot of fun and definitely check it out, it supports the show. So to continue on with my theme, it's all about the 3D and the python. So the next one I want to cover is something called Panda3D and now it may seem very similarly named to Pandas but has nothing to do with that. It's just an open source completely free to use game engine for real-time 3d games, visualizations, simulization, simulations experiments, all that kind of stuff. This one comes from Kolja Lubitz, hopefully that was close enough, thank you Kolja for sending that in that's great. One of the things that I thought was cool I don't think everyone is going to be building a game but I think a lot of people out there are doing science and experiments and visualizations and stuff like that and I think this is a great little 3d engine for simulations that just happen to be 3d and you can do them in Python.
8:43 OKKEN: Oh that's cool
8:43 KENNEDY: Yeah ain't that nice 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, so it runs all the platforms, has very little overhead because you basically get your meshes, you load them into the system and then you sort of poke at them and control them from Python, but they run like, on your GPU in C++. So really good performance as well.
9:10 OKKEN: Oh nice.
9:10 KENNEDY: Yeah. So some of the features platform portability runs on Mac, Linux and Windows, maybe Raspberry Pi, I can't remember where else, possibly other places, but the main places it has a lot of tools for handling assets, like I don't know, if you've ever done anything with 3d but like it's these library files and this Adobe file format for that other thing and there's just all that kind of stuff so there's like a lot of tools for handling these assets. Which is pretty awesome, so you can automate either your pipeline or even the code. It also has library binding which is cool so you can do things like, plugin the Bullet PhysX engine or the Assimp loader or OpenAL or all these different things that, just because you have 3D, it doesn't mean that you have physics or interaction or stuff like that, right? And then finally it comes with this thing called Pstats for Panda3D profiling, 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 takes that amount of time to run so you get like super detailed runtime profiling and performance analysis, so not bad for a completely free Python enabled thing.
10:21 OKKEN: Yeah and it's like completely free. You can even use it for commercial use if you want, with it.
10:25 KENNEDY: Yeah exactly and I don't think Unreal 4 for example is so this is a nice one.
10:30 OKKEN: Nice
10:30 KENNEDY: Yep What's the next thing you got?
10:31 OKKEN: I have an interesting article and I should have written down, it's from Dustin Ingram called why PyPI doesn't know your projects 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 KENNEDY: Yeah, you can do it on GitHub as a whole project but you can't do it as like single... You can't go, this package I'm going to get has exactly, that's nice, that would be nice.
11:02 OKKEN: He's trying to answer, he says he gets a lot of questions like "How can I produce a dependency graph for python packages? Man, why doesn't PyPI show the project dependencies right on the page?" That would be neat. "Also just how can I get all the dependencies without downloading it first?" And the answer is you can't, which is interestin. The reason is because of setup tools then setup.py is dynamic, it's code, it runs and he gives an example, which is sort of funny, he gives an example of building a setup.py package that does a dependency with random choice. So randomly pulls in different packages.
11:43 KENNEDY: Fun, just to make a point.
11:45 OKKEN: 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. But there's some real reason to do that and a lot of them have to do with different packages being available in Windows versus Linux versus Mac or whatever. So operating system dependencies are something that often makes you have to pull one in versus another also different versions of Python so if you're using Python, you want to use data classes and you're using an older python, you need to actually depend on Data classes for instance. So this is an interesting article that talks about that but also points out why wheels are awesome. So wheels are not something that are dynamic they are more predictable, so this is a, I think also a little bit of a plug for wheels. And I wanted to highlight that wheels, they have dependencies in them also but they are not as dynamic. So they'll be a different wheel for different Operating Systems. While I was poking around on here I also wanted to go a little bit of a tangent. There's a website called Pythonwheels.com that I'll just drop a link in here to and it talks about some of the advantages of wheels.
13:00 KENNEDY: It's nice, installs faster, doesn't run setup.py, yeah, doesn't require a compiler, so basically a kind of a binary version instead of a source version which is cool.
13:12 OKKEN: For some packages that have wheels up there, it is kinds 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 the different operating systems.
13:24 KENNEDY: Yeah cool, but I like it and it's a totally reasonable question, like, "I am considering installing, what does it use?" Right? That should be obvious and I'm not sure it is.
13:34 OKKEN: 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? Pip includes a command called download so you can say pip download something and point it to a directory and it will download something and all of the dependencies that are valid for your operating system so if you really curious that's one way to do it.
13:57 KENNEDY: Very cool, alright for the last one I want to talk about building games. I know there's stuff, other stuff with Python. Now this one is different than the others. The first two, it was about 3d game 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 Python but what this is actually this one makes me super excited, makes me want to go along with it is a, at least six part series on PyGame and a really quite detailed and in depth and interactive. So I should give you a sense it start out with building a simple dice game then building a game framework so you can build on top of it, adding players, moving your characters around, having heroes and villains that fight and then the last one at least by the time of the recording is putting platforms in a Python game with PyGame and what they mean by that is, think of Mario Brothers or Joust or something like one of these old 2D side scroller games like how do you create a game with that? And it's pretty elaborate and pretty nice.
14:59 OKKEN: Oh that's cool.
15:00 KENNEDY: Yeah, it's like basically the six part series so if you wanted to kind of get your Python better or you wanted to learn PyGame. Either of those, this will be a really cool set of series to go through because come up with like a 3D side scrol... oh sorry 2D side scroller game at the end and that seems pretty awesome.
15:16 OKKEN: Man, I have not thought about joust in a long time, I miss that game, that was cool.
15:19 KENNEDY: I know, I can even remember the sounds but yeah, I remember it for sure, using the arcade there, that was fun that one and Dungeon game, that was sort off just a video more or less. Those were fun times. Now, one other thing that I want to throw in here so this is the series and that was kind of what I want to talk about I'm linking to all the pieces but something I ran across recently as well that I thought was pretty cool, I haven't gotten it, I haven't play with it yet, but it gave me the same feeling of what "Oh this looks so cool!" Is this thing called Mission Python a code space adventure game so similarly it's like a whole learn Python and learn PyGame by building like a space adventure game with PyGame and it just looks so fun, I want to do it but haven't done it yet. Haven't ordered the book
16:02 OKKEN: Oh yeah, it does look fun, neat.
16:05 KENNEDY: Yeah, so if you're interested in learning PyGame or you want to use PyGame for some kind of simulation type thing, either of these will be helpful.
16:13 OKKEN: Yeah, sorry, I'm already giggling about the joke.
16:17 KENNEDY: 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 OKKEN: No, nothing extra this week, how about you?
16:32 KENNEDY: Not really, but I do want to say, I'm looking forward to being at PyCascades with you and everyone else up in Seattle end of February, so if there's still tickets available by the time this goes out and people want to make it there, then definitely check it out it was a fun conference last year.
16:45 OKKEN: Definitely.
16:46 KENNEDY: Absolutely, alright I guess we got our friend Dan Bader to thank for this, don't we?
16:50 OKKEN: I guess, I think, I'm not sure, somebody at Real Python
16:53 KENNEDY: Somebody at Real Python, alright, here comes the joke. This comes from @realpython, twitter and I linked to the joke, it's got a little graphic to it but you can do without.
17:01 OKKEN: Yeah, so why do pythons live on land?
17:03 KENNEDY: I don't know, they're snakes, I don't know why.
17:05 OKKEN: 'cause they're above C-level.
17:09 KENNEDY: The letter C, capital, dash, level, of course.
17:12 OKKEN: Yes, cause Python is a higher level language it gets worse as you explain it more.
17:19 KENNEDY: That's right, C because you don't compile it, no. It's bad, it's a good joke though very, very funny thanks for sharing.
17:26 OKKEN: Yeah, definitely, so thank you.
17:29 KENNEDY: Yeah, thanks for doing the episode as well and goodbye everyone.
17:31 OKKEN: Bye
17:32 KENNEDY: Thank you for listening to Pythonbytes. Follow the show on Twitter via @pythonbytes, that's python bytes 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 for sharing something cool. On behalf of myself and Brian Okken, this is Micheal Kennedy, thank you for listening and sharing this podcast with your friends and colleauges.