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.
And I'm Brian Okken.
And this episode is brought to you by DigitalOcean. Check them out at pythonbytes.fm/DigitalOcean.
For now, I would like to get out there and explore a dictionary. What do we got here, Brian?
This is totally cool. I don't even know what to call this.
I've got a link. It's called Inside Python Dict and 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 like 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 how...
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 like auto-playing with like a little...
It 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, because all of the code for this website is up on GitHub.
This is a cool example.
And you're right.
The little visual played, highlight the code, highlight the visual data structures animation is really great, I think.
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 on the back end.
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 superpowers.
To get really good at Python, you kind of have to really grok dictionaries.
So this is a good thing.
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.
Yeah.
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 as like Fortnite saved the world, Gears of War 4, Marvel versus Capcom, System Shock, not the old one, which is an awesome game from the 90s, but the 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 of the Unreal Engine, both for controlling editing, like automating, scripting, say loading a bunch of stuff and auto generating characters or stuff like that.
And also runtime, like even characters in the games.
Yeah, that's neat.
That's cool, right?
So yeah, so basically this is like a meta plugin.
Like you take this plugin, you stick it in 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.
Oh, wow.
Yeah, it's pretty interesting.
And the GitHub repo is super detailed in 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 some.
There's a whole bunch more than the ones I listed here.
This is a cool option here.
Yeah, nice.
Cool.
Yeah.
So this next one you got for us is on context love.
I'm a big fan of context managers in the West David.
Tell us what you found.
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 context lib 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 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.
Yeah.
And it'd be great for testing and something like that without trying to do too much.
Right.
What's cool that I like about this is because 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.
I didn't put this in the show notes, but in the link to the context lib documentation,
the output I showed in our example, just capturing it with string IO, but you can pass it in like a file.
So if you've got part of your system that usually just prints to standard out,
you can redirect all that to a file if you want to save it somewhere.
Yeah.
Nice.
And there's a standard error edition as well.
Right.
Yep.
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 as to put it into one of these, create a little context manager,
throw it in there and adjust the stuff like that interacts with a console or terminal in the width block is green.
Right.
That's pretty cool.
I like this pattern.
Very nice.
Before we move on to 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?
I have not.
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.
So you should check out digital oceans, Kubernetes, do K eight 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 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.
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/digital ocean as a new user, you'll get a hundred dollars 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 that I want to cover is something called Panda 3D.
And now it may seem very similarly named to Pandas, but it has nothing to do with that.
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.
This one comes from Kolia Lubitz.
Hopefully that was close enough.
Thank you, Kolia, for sending that in.
That's great.
One of the things I thought was cool, I don't think everyone's 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 in 3D and you can do them in Python.
Oh, that's cool.
Yeah.
Isn'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 on all the platforms.
On all the platforms.
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 like on your GPU in C++.
So really good performance as well.
Oh, nice.
Yeah.
So some of the features, platform portability, it 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.
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.
So there's 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 bindings, which is cool.
So you can do things like plug in the Bullet Physics Engine or the Asimap Loader or OpenAL or all these different things that, you know, just because you have 3D doesn't mean you have like physics or interaction and stuff like that.
Right?
Yeah.
Pretty cool.
And then finally, it comes with this thing called PStats for Panda 3D 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.
It 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.
Yeah.
And it's like completely free.
You can even use it for commercial use if you want.
Yeah, exactly.
And I don't think like Unreal 4, for example, is.
So this is a nice one.
Nice.
Yep.
What's the next thing you got?
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 in on packages on PyPI, it would be kind of cool if you could see all the dependencies of a particular package.
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 going to get has exactly.
That's nice.
It would be nice.
He's trying to answer.
He said he gets a lot of questions like, how can I produce a dependency graph for Python packages?
And why doesn't PyPI show that the project dependencies right out on the page?
That would be neat.
And also just how can I get all the dependencies without downloading it first?
And the answer is you can't, which is interesting.
And the reason is because of setup tools and 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.
Fun.
Just to make a point.
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 reasons to do that.
And a lot of them have to do with like different packages being available on Windows versus Linux versus Mac or whatever.
So operating system dependencies are something that often makes you have to pull one end versus another.
Also, different versions of Python.
So if you're using Python different, if you want to use data classes and you're using an older Python,
you need to actually depend on data classes, for instance.
Yeah.
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, 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're not as dynamic.
So there'll be a different wheel up there for different operating systems.
And while I was poking around on here, I also, I wanted to go on a little bit of a tangent.
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.
It's nice.
It installs faster.
It doesn't run setuppy.
Yeah.
It doesn't require a compiler.
So basically, kind of a binary version instead of a source version, which is cool.
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 system.
Yeah, cool.
I like it.
And it's a totally reasonable question.
Like, I'm considering installing this thing.
What does it use?
Right?
That's a little, that should be obvious.
And I'm not sure it is.
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'll download something and all of the dependencies that are valid for your operating system.
So if you're really curious, that's one way to do it.
Very, very cool.
All right.
For the last one, I want to talk about building games and other stuff, other stuff with Python.
Now, this one is different than the other.
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 Python.
But what this is, actually, this one makes me super excited.
It makes me want to go along with it.
It's a at least six-part series on Pygame.
And they're really quite detailed and in-depth and interactive.
So I'll just give you a sense.
It starts out with building a simple dice game and 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 at the time of the recording, is putting platforms in a Python game with Pygame.
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.
Like, how do you create a game with that?
And it's pretty elaborate and pretty nice.
Oh, that's cool.
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 would be a really cool set of series to go through because you're going to come up with like a 2D side-scroller game at the end.
And that seems pretty awesome.
Man, I haven't thought about Joust in a long time.
I missed that game.
That was cool.
I know.
I can't even remember the sounds.
But yeah, I remember it for sure.
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.
But those were fun times.
Yeah.
Now, one other thing that I want to throw in here.
Like, 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 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.
So similarly, it's like a whole learn Python and learn Py game by building like a space adventure game with Py game.
And it just looks so fun.
I just, I don't want to do it, but haven't done it yet.
Haven't ordered the book.
Oh, yeah, it does look fun.
Yeah.
So if you're interested in learning Py game or you want to use Py game for some kind of simulation type thing, either of these would be real helpful.
Yeah.
Sorry.
I'm already giggling about the joke.
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?
No, nothing extra this week.
How about you?
Not really.
But I do want to say I'm looking forward to being at Py Cascades with you and everyone else up in Seattle into 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.
Definitely.
Absolutely.
All right.
I guess we got our friend Dan Bader to thank for this, don't we?
I guess.
I think.
I'm not sure.
Somebody at RealPython.
Yeah, somebody at RealPython.
All right.
Hit us with a joke.
This comes from the RealPython Twitter and I linked to the joke.
It's got a little graphic to it, but you can do it without.
Yeah.
So why do Pythons live on land?
I don't know.
They're snakes.
I don't know why.
Because they're above sea level.
The letter C, capital dash level, of course.
Yeah.
Because Python's a higher level language.
You know, it gets worse as you explain it more.
That's right.
See, because you don't compile it.
No.
Yeah, it's bad.
It's a good joke, though.
And very, very funny.
Thanks for sharing.
Yeah, definitely.
So thank you.
Yeah.
Thanks for doing the episode as well.
And goodbye, everyone.
Bye.
Thank you for listening to Python Bytes.
Follow the show on Twitter via at Python Bytes.
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 Michael Kennedy.
Thank you for listening and sharing this podcast with your friends and colleagues.