WEBVTT

00:00:00.001 --> 00:00:04.640
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.

00:00:04.640 --> 00:00:11.440
This is episode 134, recorded June 3rd, 2019. I'm Michael Kennedy.

00:00:11.440 --> 00:00:12.260
And I'm Brian Okken.

00:00:12.260 --> 00:00:13.980
And this episode is brought to you by DigitalOcean.

00:00:13.980 --> 00:00:18.640
I feel like I've been lied to. I feel like the world is not as I expected it to be.

00:00:18.640 --> 00:00:22.960
I was taught about planets first in school, and first I was told there were nine.

00:00:22.960 --> 00:00:28.320
And of course, I was told that Mercury was the closest to the sun, and then Venus, and then the Earth.

00:00:28.320 --> 00:00:32.900
And yet, you're telling me Python here may be disproving this? What's the story here?

00:00:32.900 --> 00:00:35.080
So which planet is closest to Earth?

00:00:35.080 --> 00:00:40.840
Mercury. Wait, no, Venus, because it goes Mercury, and then Venus, and then Earth, and then Mars, and so on.

00:00:40.840 --> 00:00:49.540
And the orbits are farther out, and if you look at it to scale, it looks like the orbit of Venus and the orbit of Earth are closer together.

00:00:49.540 --> 00:00:49.820
Yes.

00:00:49.820 --> 00:00:55.620
And that is true. However, they spend as much time the closest.

00:00:55.620 --> 00:01:10.520
On average, if you take the average, how of the exact locations and the exact distance or exact ish, actually all of the planets spend more time closer to the sun than they do to each other, because that's just how that works.

00:01:10.960 --> 00:01:18.840
And since Mercury is closest to the sun, it is on average closest to all the other planets.

00:01:18.840 --> 00:01:24.740
There's a nice video on this link, so I'm linking to an article called, I even did it wrong.

00:01:24.880 --> 00:01:31.560
So three scientists published a paper proving that Mercury, not Venus, is the closest planet to the Earth using Python.

00:01:31.560 --> 00:01:41.340
It's a nice article about using the graph, and they graph it all out, and it's kind of neat that you just watch it, and you're like, oh yeah, well, of course.

00:01:41.340 --> 00:01:47.820
As you watch these planets circle the sun, then you calculate the distance, and then you do an average.

00:01:48.260 --> 00:01:54.220
It's close, so the average, Mercury is closest to the Earth 43% of the time.

00:01:54.220 --> 00:01:58.280
Venus is closest to the Earth 37% of the time.

00:01:58.280 --> 00:02:00.460
So Mercury wins.

00:02:00.460 --> 00:02:00.840
Wow.

00:02:00.840 --> 00:02:01.120
Yeah.

00:02:01.120 --> 00:02:01.900
That's really wild.

00:02:01.900 --> 00:02:03.160
I guess that makes sense, right?

00:02:03.160 --> 00:02:11.020
Because all the planets are roughly, continuously the same distance from the sun, but they're often out of phase with each other, right?

00:02:11.020 --> 00:02:16.300
They might be on opposite sides of the sun, which puts them super far apart, even though their orbits could actually be close together.

00:02:16.300 --> 00:02:22.480
Yeah, and also the orbits that are far away from the sun, those take longer time, right?

00:02:22.480 --> 00:02:30.620
So they're spending more time really far from the sun, and if you're really far on the other side of the sun from another planet, you're, yeah, it's just far.

00:02:30.620 --> 00:02:31.380
Yeah, you're super far away.

00:02:31.380 --> 00:02:32.100
Yeah, absolutely.

00:02:32.100 --> 00:02:41.100
And they were linking the article and the video used a library called PyEphem, I think, P-E-Y-E-P-H-E-M.

00:02:41.580 --> 00:02:50.780
Apparently, according to Andrew Diedrich, that contributed this for this show, has been largely deprecated and replaced with another library called Skyfield.

00:02:50.780 --> 00:02:57.760
And I took a look at that, and it looks like a really fun library to easily get data about the solar system and stuff.

00:02:57.760 --> 00:02:58.700
Yeah, that looks super cool.

00:02:58.820 --> 00:03:06.280
I got to say, one of the areas that sparks the most wonder and amazement in the use of Python is astronomy, for me personally.

00:03:06.280 --> 00:03:16.340
Yeah, it's neat to even have some of these little things of, like, an average person can go, wait, I don't think that's right, and just map it out using some Python.

00:03:16.340 --> 00:03:16.760
Yeah.

00:03:16.860 --> 00:03:19.680
And then you can come up with these different conclusions.

00:03:19.680 --> 00:03:20.260
It's great.

00:03:20.260 --> 00:03:21.100
Yeah, super cool.

00:03:21.100 --> 00:03:22.920
Well, thanks for finding that one.

00:03:22.920 --> 00:03:23.300
That's great.

00:03:23.300 --> 00:03:30.020
Last week, I covered a couple of GitHub topics that I thought were really interesting, sponsors and Dependabot.

00:03:30.020 --> 00:03:35.620
And I'm back this time, this week, with a slightly different theme that also intersects GitHub.

00:03:35.860 --> 00:03:43.240
So I feel like I have a theme this week, and the theme is understanding languages, like the internals and the inner workings of languages better.

00:03:43.240 --> 00:03:49.500
So the first thing I want to talk about is this library that was released called GitHub Semantics.

00:03:49.500 --> 00:03:57.000
So GitHub, they have, as you know, many different programming languages and all sorts of cool analytics and reporting and whatnot.

00:03:57.000 --> 00:04:03.520
So they built this library that will help them make comparisons across languages.

00:04:03.520 --> 00:04:09.700
Like, if you wanted to ask the question of, what is the average psycholomatic complexity by language?

00:04:09.700 --> 00:04:13.500
Studying the top 100 repos or whatever, something like that.

00:04:13.500 --> 00:04:20.120
You could answer that across Python, TypeScript, JavaScript, Ruby, Go, and some other languages as well.

00:04:20.120 --> 00:04:20.620
Weird.

00:04:20.620 --> 00:04:21.540
That's cool.

00:04:21.540 --> 00:04:22.080
Isn't that cool?

00:04:22.080 --> 00:04:30.160
So it's not something in terms of, like, digging into it that a lot of Python developers are going to be super excited about because it's written in Haskell.

00:04:30.160 --> 00:04:36.420
But you can also just use it as a command line tool for parsing and analyzing and comparing source code across languages.

00:04:36.420 --> 00:04:36.980
Oh, neat.

00:04:36.980 --> 00:04:39.260
It does some interesting stuff.

00:04:39.260 --> 00:04:49.280
And, like, some of the things that you can do with it, or it has in it, I guess, is a flow-sensitive caching interpreter for imperative languages.

00:04:49.980 --> 00:04:55.080
It has an abstract interpreter for generating scope graphs within given program text.

00:04:55.080 --> 00:05:01.880
So if you want to compare scope across different languages, like, compare two different functions that are trying to do the same thing or something.

00:05:01.880 --> 00:05:06.940
And then a strategic rewriting system for open syntax terms.

00:05:06.940 --> 00:05:10.460
So not a whole lot of stuff that I feel like I'm going to be doing day to day.

00:05:10.540 --> 00:05:19.060
But if you're in a computer science program, if you're trying to study languages or make generalizations or maybe even tooling, I think this would be pretty interesting to check out.

00:05:19.060 --> 00:05:19.240
Yeah.

00:05:19.240 --> 00:05:20.460
Is it written in Haskell?

00:05:20.460 --> 00:05:20.840
It is.

00:05:20.840 --> 00:05:22.060
Yeah, it's written in Haskell.

00:05:22.060 --> 00:05:22.280
Yeah.

00:05:22.280 --> 00:05:22.840
Okay.

00:05:22.840 --> 00:05:23.240
Cool.

00:05:23.240 --> 00:05:23.440
Yep.

00:05:23.440 --> 00:05:25.520
And this one comes from Oren Carmi.

00:05:25.520 --> 00:05:27.320
So I just want to say thanks for sending that over.

00:05:27.320 --> 00:05:29.260
We always appreciate getting those ones passed along.

00:05:29.260 --> 00:05:30.040
What do you got next?

00:05:30.160 --> 00:05:32.700
Well, we've talked about black, I think, several times.

00:05:32.700 --> 00:05:34.240
And I like using black.

00:05:34.240 --> 00:05:39.820
One of the things that bothers me a little bit is having something change my code without me knowing about it.

00:05:39.820 --> 00:05:40.040
Yeah.

00:05:40.040 --> 00:05:47.820
There's a flag called black-check that will basically tell you if you ran it, this is what it would do.

00:05:47.820 --> 00:05:55.040
I also use flake8 to check stuff, like to sort of lint my code and help me understand what I'm...

00:05:55.040 --> 00:05:57.720
Actually, I like it that it doesn't...

00:05:57.720 --> 00:05:58.960
Flake8 doesn't change your stuff.

00:05:59.040 --> 00:06:01.020
It just tells you some information.

00:06:01.020 --> 00:06:04.620
And so you can train yourself to write in a more consistent way.

00:06:04.620 --> 00:06:07.720
So this is contributed by Nathan Clayton.

00:06:07.720 --> 00:06:20.360
There's a flake8 black plugin that can just run black check within a flake8 environment and tell you if you ran black, it would change this stuff along with all your other flake8 checks.

00:06:20.360 --> 00:06:24.460
I think this is pretty handy, and I'll try to include this into my workflow.

00:06:24.460 --> 00:06:28.240
Yeah, and that probably makes it pretty easy to plug in to continuous integration pipelines,

00:06:28.240 --> 00:06:32.020
because flake8 may already be part of some continuous integration check, right?

00:06:32.020 --> 00:06:36.140
A lot of people are hooking black into a pre-commit hook, which is great.

00:06:36.140 --> 00:06:37.180
You can also hook...

00:06:37.180 --> 00:06:40.460
If you're already hooking flake8 up in a pre-commit hook, you can do this as well.

00:06:40.460 --> 00:06:45.180
But having it, you can still slip stuff in and merges might muck things up.

00:06:45.180 --> 00:06:46.460
So yeah, this is cool.

00:06:46.460 --> 00:06:46.880
Yeah, yeah.

00:06:46.880 --> 00:06:47.280
Super cool.

00:06:47.360 --> 00:06:53.020
And you can't necessarily be sure everyone is running all the same tooling or whatever, right?

00:06:53.020 --> 00:06:54.780
So maybe they've changed it somehow.

00:06:54.780 --> 00:06:56.000
So this will check it.

00:06:56.000 --> 00:06:56.400
Very cool.

00:06:56.400 --> 00:06:57.060
That's a good one.

00:06:57.060 --> 00:06:57.480
All right.

00:06:57.480 --> 00:07:00.520
Now, before we get to the next one, I want to tell you all about DigitalOcean.

00:07:00.780 --> 00:07:06.360
They're sponsoring this episode, as they do many of them, and make this show certainly possible in some way.

00:07:06.360 --> 00:07:07.680
So thank you to them.

00:07:07.680 --> 00:07:10.300
And they are doing all sorts of cool stuff.

00:07:10.300 --> 00:07:11.940
You know, we use them for our infrastructure.

00:07:12.800 --> 00:07:15.460
They have great virtual machine support.

00:07:15.460 --> 00:07:21.480
But one of the things they recently rolled out was managed Postgres servers or as a service.

00:07:21.480 --> 00:07:27.160
So if you want to create something on Linux and get it up and running fast, affordable, simply,

00:07:27.160 --> 00:07:32.360
but you don't want to also become a DBA and manage your own database, your own backups and all that,

00:07:32.360 --> 00:07:36.680
you can just plug into their managed database service for Postgres over there.

00:07:36.680 --> 00:07:42.780
And that's one less thing to, you know, own as a puppy or to have to babysit all the time and patch and whatnot.

00:07:42.780 --> 00:07:45.280
So definitely recommend checking them out.

00:07:45.280 --> 00:07:46.220
They're doing cool stuff.

00:07:46.220 --> 00:07:51.680
So visit them over at pythonbystat.fm slash digitalocean, and you'll get a $50 credit for new users.

00:07:51.680 --> 00:07:55.740
Now, back onto my theme here for understanding languages.

00:07:55.740 --> 00:08:04.760
If you look at the popular editors these days, Brian, we have PyCharm and we have VS Code as the two, like, frontrunners, I would say, these days.

00:08:04.760 --> 00:08:08.220
It's kind of like if you want a big ID that's going to do everything for you, PyCharm.

00:08:08.220 --> 00:08:15.660
If you have a lighter weight preference, then maybe VS Code seems to be like what a lot of folks are trending towards.

00:08:15.660 --> 00:08:21.160
So there's this cool extension for VS Code called Python Preview.

00:08:21.160 --> 00:08:30.440
If you're a computer science student or if you're getting into Python and you want to have a good understanding of what's happening as you're writing code,

00:08:30.440 --> 00:08:32.520
I think using this extension is awesome.

00:08:32.720 --> 00:08:40.520
So click on the link there and just look at the little picture that gets drawn if you scroll down to the second picture or something like that there.

00:08:40.520 --> 00:08:40.960
Okay.

00:08:40.960 --> 00:08:41.860
This is neat.

00:08:41.860 --> 00:08:43.700
So what happens is you write some Python code.

00:08:43.700 --> 00:08:48.400
You maybe create a list, and then you're going to loop over it, and you're going to change the variable or something like that.

00:08:48.460 --> 00:08:57.000
And it will create a visualization of what the objects look like in memory, what the call stack looks like, the global frame is, and all that.

00:08:57.000 --> 00:09:03.040
And it will actually show all the pointer references between the variables and how they're changing and what type they are.

00:09:03.040 --> 00:09:10.260
All sorts of interesting stuff as it just sort of, like, explains what your code is doing visually if you were to run it.

00:09:10.260 --> 00:09:11.360
Oh, this is really cool.

00:09:11.360 --> 00:09:11.920
I like it.

00:09:11.920 --> 00:09:12.120
Yeah.

00:09:12.120 --> 00:09:12.900
It's really cool.

00:09:12.900 --> 00:09:16.220
It's free because it's just part of VS Code, so that's really nice.

00:09:16.220 --> 00:09:27.500
So if you're either a student or trying to learn the language or if you're a teacher, right, like, this is exactly the kind of stuff you're like, well, let's look at this code, and now I'm going to go over and draw it out on the whiteboard.

00:09:27.500 --> 00:09:30.580
Like, oh, you could just let this thing draw it perfectly, right?

00:09:30.580 --> 00:09:31.120
You know what I mean?

00:09:31.120 --> 00:09:31.380
Yeah.

00:09:31.380 --> 00:09:37.900
So I think this would actually be really good for an intro language course if you do any teaching or something like that.

00:09:37.900 --> 00:09:38.200
Yeah.

00:09:38.200 --> 00:09:39.100
I like it.

00:09:39.100 --> 00:09:39.280
Yeah.

00:09:39.280 --> 00:09:40.860
It reminds me of Python Tutor.

00:09:40.860 --> 00:09:53.440
It should remind you of Python Tutor because if you look at the GitHub repo for this extension, it actually says, I would like to thank a couple of projects for at least conceptually inspiring me.

00:09:53.440 --> 00:09:55.640
I don't know that there's any code sharing or anything like that.

00:09:55.640 --> 00:10:00.220
And the first one is Philip Guo's pythontutor.com site.

00:10:00.840 --> 00:10:01.280
Okay.

00:10:01.280 --> 00:10:02.320
Well, that makes sense.

00:10:02.320 --> 00:10:03.400
Yeah, it definitely makes sense.

00:10:03.400 --> 00:10:08.480
If you've played with Python Tutor before, that's a place to go explore Python, and you type it in there.

00:10:08.480 --> 00:10:13.220
And what's cool about this is, like, it just explores the code that you have open in your editor in a similar way.

00:10:13.220 --> 00:10:14.840
You can't step through it, I don't believe.

00:10:14.840 --> 00:10:16.320
But, yeah, it's pretty cool.

00:10:16.320 --> 00:10:16.560
Yeah.

00:10:16.560 --> 00:10:17.000
Neat.

00:10:17.000 --> 00:10:17.300
Awesome.

00:10:17.300 --> 00:10:18.000
All right.

00:10:18.000 --> 00:10:18.480
What's next?

00:10:18.480 --> 00:10:20.180
Something we haven't talked about before, huh?

00:10:20.180 --> 00:10:20.580
Packaging?

00:10:20.580 --> 00:10:22.440
Packaging and poetry.

00:10:22.440 --> 00:10:28.860
This is a nice article called Create and Publish a Python Package with Poetry by John Franey.

00:10:29.460 --> 00:10:34.260
There's been, occasionally people will say poetry is more for projects or something.

00:10:34.260 --> 00:10:36.340
But this is dealing with a Python package.

00:10:36.340 --> 00:10:43.980
And it walks through creating a new project and then customizing the pyproject.toml file.

00:10:44.240 --> 00:10:48.660
And then all the different settings within the toml and what do they mean and why you pick different ones.

00:10:48.660 --> 00:10:53.880
And then carries you through to, if it's something you were going to share with the rest of the world.

00:10:53.880 --> 00:10:57.960
I mean, one of the great things about all this is you don't have to share your code with the world.

00:10:57.960 --> 00:11:03.900
You might be just sharing it with your team members or just even making modularizing your own stuff.

00:11:04.080 --> 00:11:10.940
But if you do want to share it, it does show you how to use the test server at PyPI to try everything out and make sure it works.

00:11:10.940 --> 00:11:14.220
And then finally to publish directly to PyPI.

00:11:14.220 --> 00:11:14.540
Yeah.

00:11:14.540 --> 00:11:16.120
It looks like a really nice little write-up.

00:11:16.120 --> 00:11:20.220
And yeah, it's just typing poetry space publish.

00:11:20.220 --> 00:11:21.280
That's not terrible.

00:11:22.280 --> 00:11:22.640
Yeah.

00:11:22.640 --> 00:11:29.160
It doesn't talk about testing or integrating testing and talks into a project, which, and pytest, of course.

00:11:29.160 --> 00:11:31.260
But so that maybe that's an extension.

00:11:31.260 --> 00:11:33.220
But yeah, this is the packaging part.

00:11:33.220 --> 00:11:33.720
Yeah, cool.

00:11:33.720 --> 00:11:34.620
Maybe a follow-up article.

00:11:34.620 --> 00:11:35.360
That'd be great.

00:11:35.360 --> 00:11:36.420
Very nice one.

00:11:36.420 --> 00:11:41.560
So the last one that I want to cover is a realpython.com article by Logan Jones.

00:11:41.560 --> 00:11:43.840
We got to hang out with him a little bit at PyCon.

00:11:43.840 --> 00:11:44.660
That was fun.

00:11:44.660 --> 00:11:51.920
But this one is, I think, an interesting sort of thought-provoking one about Python and the language.

00:11:52.240 --> 00:11:54.840
So I think there's a lot to learn here for many folks.

00:11:54.840 --> 00:11:58.600
And it's called Python Pointers or Pointers in Python, What's the Point?

00:11:58.600 --> 00:12:06.440
So, I mean, first of all, like the question is like outside of C extensions and maybe like inside the CPython runtime.

00:12:06.440 --> 00:12:11.720
But, you know, in Python, the language itself, does Python even have pointers, right?

00:12:11.720 --> 00:12:12.620
Like, what do you think?

00:12:12.620 --> 00:12:14.480
How would you answer that question if somebody asked you that?

00:12:14.480 --> 00:12:16.860
It's mostly hidden from users.

00:12:16.860 --> 00:12:17.220
Exactly.

00:12:17.220 --> 00:12:17.480
Yeah.

00:12:17.480 --> 00:12:18.980
If someone asked me, does Python have pointers?

00:12:18.980 --> 00:12:20.640
I would say, yeah, of course it has pointers.

00:12:20.940 --> 00:12:31.360
But it really hinges on whether or not you define that as I can put an ampersand in front and then like plus plus it and move in the, you know, move along in like a string or move along in an array.

00:12:31.360 --> 00:12:35.360
Like, can I do pointer arithmetic and can I actually work at that level?

00:12:35.540 --> 00:12:41.200
Or is it I have variables that point out to things on the heap like pointers, right?

00:12:41.200 --> 00:12:44.520
Like, which of those has to pass the bar to be like it's a pointer, right?

00:12:44.520 --> 00:12:45.060
Yeah.

00:12:45.060 --> 00:12:50.920
And generally, a new person to point Python and programming altogether wouldn't even notice them and would say no.

00:12:50.920 --> 00:12:53.560
But, I mean, like names are all pointing to stuff.

00:12:53.560 --> 00:12:54.140
Exactly.

00:12:54.380 --> 00:12:58.040
So, what's really interesting is that could be a big misconception, right?

00:12:58.040 --> 00:13:06.620
Because if you think what you're passing around are values, but you actually have pointers, anytime you change one of those things, you're changing it everywhere, right?

00:13:06.620 --> 00:13:09.660
You have passed by reference, not passed by value semantics.

00:13:10.440 --> 00:13:16.580
And so, if you think I can pass this over, that thing can change it and it doesn't affect me like a normal value would, right?

00:13:16.580 --> 00:13:19.100
Like, whoops, that's a bit of a problem, right?

00:13:19.100 --> 00:13:26.080
We've seen like weird edge cases where like the default value of like an empty list in a function can be all sorts of badness for reasons like that.

00:13:26.080 --> 00:13:26.960
So, I don't know.

00:13:26.960 --> 00:13:27.640
It's pretty interesting.

00:13:27.640 --> 00:13:37.040
I think actually Python is more pointer heavy than most languages, more so than C#, more so than C++, right?

00:13:37.040 --> 00:13:45.080
Because in those languages, you at least have the option to define stuff on the stack and define value types like integers versus in pointers in C++, right?

00:13:45.080 --> 00:13:46.300
In Python, you really don't.

00:13:46.300 --> 00:13:49.780
Everything, even numbers and booleans and stuff are pointers, right?

00:13:49.780 --> 00:13:51.680
I didn't know that, but okay.

00:13:51.680 --> 00:13:52.540
Yeah.

00:13:52.540 --> 00:13:55.060
So, like true is a pointer out on the heap.

00:13:55.060 --> 00:13:57.420
The number seven is a pointer on the heap.

00:13:57.420 --> 00:14:00.620
So, what it means is like all sorts of, you know, it really helps you.

00:14:00.620 --> 00:14:03.200
If you look, and the article goes through a lot of this.

00:14:03.200 --> 00:14:12.380
If you look deeply at like the memory structure of what you get, you know, each reference type, which I'll call them, you know, thing in Python.

00:14:12.380 --> 00:14:17.400
Each object, so everything, has a reference count it has to keep track of.

00:14:17.880 --> 00:14:32.020
It has a type, like so, in the pi object that actually gets allocated when you say the number one or whatever, that has actually a field up there that says this is an integer right now.

00:14:32.020 --> 00:14:35.900
This pi object that it's pointing at is supposed to be an integer, and it has a value.

00:14:36.560 --> 00:14:46.700
So, if you think of, I've got this simple little piece of data, like the number one or the character C, it's not just one byte or four bytes or whatever.

00:14:46.700 --> 00:14:48.560
It's many of those.

00:14:48.560 --> 00:14:50.800
I don't know, 2025, 28.

00:14:50.800 --> 00:14:57.600
I'm not sure exactly what the number is, but there's a lot of stuff coming along with that, what would otherwise look like a really simple little value.

00:14:57.740 --> 00:14:58.600
Yeah, okay.

00:14:58.600 --> 00:14:58.980
Okay.

00:14:58.980 --> 00:15:06.360
There's some nice drawings in there about like that names are pointing to objects, and objects all have types and values and reference counts.

00:15:06.360 --> 00:15:08.600
And yeah, this is good.

00:15:08.600 --> 00:15:09.620
I probably need to.

00:15:09.620 --> 00:15:16.880
Yeah, I think people should read this who haven't deeply thought about like this whole reference type scenario and what that means.

00:15:16.880 --> 00:15:17.540
It's pretty cool.

00:15:17.900 --> 00:15:20.300
My takeaway is like Python has pointers.

00:15:20.300 --> 00:15:29.560
All the variables in Pythons are pointers, but they're like these safe reference type, wrapper type things that you don't directly have to worry about, allocate, whatever, right?

00:15:29.560 --> 00:15:29.900
Yeah.

00:15:29.900 --> 00:15:30.640
So, pretty cool.

00:15:30.640 --> 00:15:38.080
There's one interesting little thing that I saw in the article that Logan talked about, and that was about interning objects.

00:15:38.740 --> 00:15:45.020
So, when I said earlier before, when I say the number one, it actually allocates a Py object on the heap, sort of.

00:15:45.020 --> 00:15:55.620
There was a Py object allocated on the heap that corresponds to one, but the first 256, something like that, numbers are what are called interned, and so are certain strings.

00:15:55.620 --> 00:16:04.500
And that means like if you allocate a one over here and you allocate a one over there, those are actually reusing the same object, right?

00:16:04.500 --> 00:16:11.120
So, they pre-allocate like the basic numbers and strings, and then you just change where your pointer points.

00:16:11.120 --> 00:16:13.400
Like that's just part of like Python startup.

00:16:13.400 --> 00:16:13.780
Okay.

00:16:13.780 --> 00:16:14.080
Right?

00:16:14.080 --> 00:16:14.980
So, that's called interning.

00:16:14.980 --> 00:16:19.580
And the interesting bit is that you can manually intern things.

00:16:19.580 --> 00:16:22.720
Like I can go to the system and say, this thing, I want to intern it.

00:16:22.720 --> 00:16:24.220
So, if someone else tries to create one of them.

00:16:24.220 --> 00:16:24.640
Oh, really?

00:16:24.640 --> 00:16:26.800
Just, you know, don't reallocate it.

00:16:26.800 --> 00:16:29.980
Just share this sort of global one-off thing I've created.

00:16:30.380 --> 00:16:36.480
And so, it says you can intern strings, and this can be useful for the performance on dictionary lookedups.

00:16:36.480 --> 00:16:47.120
Because if the strings that are the keys of the dictionary are interned, then a dictionary lookup is a pointer comparison versus a string comparison.

00:16:47.120 --> 00:16:49.040
Okay.

00:16:49.040 --> 00:16:49.980
Okay.

00:16:49.980 --> 00:16:50.780
Isn't that cool?

00:16:50.780 --> 00:16:51.040
Yeah.

00:16:51.040 --> 00:16:54.320
So, basically, it's an is versus a double equal, right?

00:16:54.320 --> 00:16:54.820
Okay.

00:16:54.900 --> 00:17:01.820
And if you've got a big dictionary and you're like going crazy on it and the keys are kind of complicated, that could potentially make it quite a bit faster.

00:17:01.820 --> 00:17:03.420
Like much, much faster.

00:17:03.420 --> 00:17:09.920
It's like, are these two integers or longs the same versus I got to go through like 20 characters and compare them?

00:17:09.920 --> 00:17:12.700
Well, so, there must be some reason why we don't just intern everything.

00:17:12.700 --> 00:17:14.380
If you intern it, it won't expire.

00:17:14.380 --> 00:17:15.400
It won't be cleaned up.

00:17:15.400 --> 00:17:16.300
Oh, okay.

00:17:16.300 --> 00:17:16.800
Yeah, yeah.

00:17:16.800 --> 00:17:22.440
So, I mean, like if you're not going to keep it around and share it, you would basically be doing manually memory management stuff.

00:17:22.440 --> 00:17:23.300
All right.

00:17:23.300 --> 00:17:26.020
So, all of that is, I think, is super interesting and worth people checking out.

00:17:26.020 --> 00:17:30.500
But now the question comes down like, can I have ampersand X?

00:17:30.500 --> 00:17:33.580
Can I get my actual pointer or star X, right?

00:17:33.580 --> 00:17:37.680
Can I do real pointer stuff in Python?

00:17:37.680 --> 00:17:42.700
And, of course, Python has to interact with C, and C functions often take this type of pointer, that type of pointer.

00:17:42.700 --> 00:17:44.460
So, how does that work, right?

00:17:44.820 --> 00:17:49.020
So, in C++, we have like inline assembly.

00:17:49.020 --> 00:17:50.620
You can kind of drop down to a lower bit.

00:17:50.620 --> 00:17:55.100
In C#, you have unsafe mode because C# has reference types just like Python.

00:17:55.100 --> 00:17:59.460
But there's a way to say, turn that off and let me actually do pointer arithmetic on it.

00:17:59.460 --> 00:18:02.640
So, the question is, can we have that in Python?

00:18:02.640 --> 00:18:05.700
And actually, if you use Cython, you can.

00:18:05.700 --> 00:18:11.560
Like in Python code, you can say, this is a pointer, and you can dereference its address by saying ampersand and stuff like that.

00:18:11.560 --> 00:18:13.160
That's one way.

00:18:13.160 --> 00:18:15.600
And you can also work with the C types library.

00:18:15.600 --> 00:18:22.320
So, I can create like an integer pointer by allocating a C type and then pass it around and share it and stuff.

00:18:22.320 --> 00:18:23.420
Okay.

00:18:24.160 --> 00:18:32.400
So, yes, if you need to dig down and you need to like truly simulate what pointers really, really are, you can actually do that in Python as well.

00:18:32.400 --> 00:18:33.840
And there's two ways to do it there.

00:18:33.840 --> 00:18:34.520
Okay.

00:18:34.520 --> 00:18:37.140
One requires Cython and one is just like straight CPython.

00:18:37.140 --> 00:18:38.220
All right.

00:18:38.220 --> 00:18:40.840
Have you had enough language lessons for today, Ryan?

00:18:41.080 --> 00:18:43.660
Or you could just not worry about it so much.

00:18:43.660 --> 00:18:44.840
But, okay.

00:18:45.440 --> 00:18:45.760
Exactly.

00:18:45.760 --> 00:18:52.120
I do think it's worth thinking about this question and like what it looks like in Python if you haven't thought about it before.

00:18:52.120 --> 00:18:58.280
And I think the thing before, the preview Python plugin or extension for VS Code, I think would also help with this.

00:18:58.280 --> 00:18:58.500
Yeah.

00:18:58.580 --> 00:19:01.560
Yeah, because it has the little lines that are really the references and so on.

00:19:01.560 --> 00:19:01.760
Yep.

00:19:01.760 --> 00:19:03.560
So, that's it for all of our topics today.

00:19:03.560 --> 00:19:04.360
Anything else?

00:19:04.360 --> 00:19:06.580
Any extra stuff you want to just throw out there real quick?

00:19:06.580 --> 00:19:11.420
Well, I was going to talk about the PSF fundraiser, but you've got it on your list too.

00:19:11.420 --> 00:19:12.040
So.

00:19:12.720 --> 00:19:15.920
Yeah, it looks like I, in terms of writing it down, I beat you to it.

00:19:15.920 --> 00:19:17.240
So, I guess I'll say something about it.

00:19:17.240 --> 00:19:19.680
So, the PSF is doing a fundraiser.

00:19:19.680 --> 00:19:20.960
I'm linked over to it.

00:19:20.960 --> 00:19:21.940
You should definitely check it out.

00:19:21.940 --> 00:19:29.760
On the previous episode, we also sort of talked about that you can buy a PyCharm license and some of that money, like 30% or something, goes towards the PSF.

00:19:29.760 --> 00:19:32.480
Or you can just directly contribute to it.

00:19:32.480 --> 00:19:34.780
So, I've linked to the blog post that they just posted.

00:19:34.780 --> 00:19:43.640
Now, the deadline was supposed to be June 1st, I believe, but they didn't raise enough money, which is mind-blowing to me.

00:19:43.640 --> 00:19:48.300
But they didn't raise enough money, so they've extended it until June 30th.

00:19:48.300 --> 00:19:55.420
So, please click on the link, donate something, and more importantly, maybe try to get your company to donate.

00:19:55.420 --> 00:19:55.940
Right?

00:19:55.940 --> 00:20:03.500
If your company deeply depends on Python having a vibrant ecosystem, these are tax-deductible if you pay taxes in the U.S., so definitely check it out.

00:20:03.500 --> 00:20:13.660
People don't know the PSF money goes to help fund workshops and conferences, and they help pay meetup fees around so that a lot of the local Python meetups don't have to pay their own fees.

00:20:13.660 --> 00:20:19.660
They do a lot of sponsorship and financial aid of different projects that should be funded but aren't otherwise.

00:20:19.660 --> 00:20:21.460
So, it's a good thing.

00:20:21.460 --> 00:20:22.280
Donate to it.

00:20:22.280 --> 00:20:22.640
Absolutely.

00:20:22.640 --> 00:20:23.260
All right.

00:20:23.260 --> 00:20:24.880
I think it's time for a joke.

00:20:24.880 --> 00:20:25.200
Yeah.

00:20:25.200 --> 00:20:26.560
Quick little one here at the end.

00:20:26.560 --> 00:20:28.100
This one comes from Jay Miller.

00:20:28.300 --> 00:20:34.560
And the question is, what did the developer name his newborn son?

00:20:34.560 --> 00:20:35.840
Of course, Jason.

00:20:35.840 --> 00:20:36.920
Jason.

00:20:36.920 --> 00:20:37.660
That's right.

00:20:37.660 --> 00:20:39.200
Oh, dear.

00:20:39.200 --> 00:20:39.860
Oh, wow.

00:20:39.860 --> 00:20:40.200
Yeah.

00:20:40.200 --> 00:20:40.980
Yeah, that's a good one.

00:20:40.980 --> 00:20:41.760
Thank you, Jay.

00:20:41.760 --> 00:20:43.640
And Brian, thanks for being here.

00:20:43.640 --> 00:20:44.000
All right.

00:20:44.000 --> 00:20:44.420
Thank you.

00:20:44.420 --> 00:20:44.760
Bye.

00:20:44.760 --> 00:20:45.060
Yep.

00:20:45.060 --> 00:20:45.300
See ya.

00:20:45.440 --> 00:20:47.220
Thank you for listening to Python Bytes.

00:20:47.220 --> 00:20:49.740
Follow the show on Twitter via at Python Bytes.

00:20:49.740 --> 00:20:52.600
That's Python Bytes as in B-Y-T-E-S.

00:20:52.600 --> 00:20:55.840
And get the full show notes at pythonbytes.fm.

00:20:55.840 --> 00:21:00.040
If you have a news item you want featured, just visit pythonbytes.fm and send it our way.

00:21:00.040 --> 00:21:02.740
We're always on the lookout for sharing something cool.

00:21:02.740 --> 00:21:05.860
On behalf of myself and Brian Okken, this is Michael Kennedy.

00:21:05.860 --> 00:21:09.280
Thank you for listening and sharing this podcast with your friends and colleagues.

