Latest / Talk Python To Me / #243: Python on Windows is OK, actually
Transcript
- 0:00We all love the Python language, but it's the 200,000 plus packages that actually make Python
- 0:05incredibly useful and productive. But installing these packages and even installing Python itself
- 0:11can vary across the different platforms. In particular, Windows has had a hard time.
- 0:17Many of the library authors don't use Windows, and so they don't test their packages on that
- 0:22platform. Tutorial authors often start their tutorial steps by activating a virtual environment.
- 0:28That's great. That's the great first step, but it is usually source venv slash bin slash activate,
- 0:34and that doesn't work on Windows. Yet over 50% of all developers programming in Python do so on
- 0:41Windows. In this episode, we'll welcome back Steve Dower. He works at Microsoft and is a Python core
- 0:47developer. He has a bunch of statistics around Python and Windows for us. He also has tons of
- 0:52good news on how Python and Windows is getting much better. This is Talk Python To Me, episode
- 0:58243, recorded on location at Microsoft Ignite in Orlando, Florida, November 8th, 2019.
- 1:04Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem,
- 1:22and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where I'm at,
- 1:27mkennedy. Keep up with the show and listen to past episodes at talkpython.fm, and follow the show on
- 1:32Twitter via at talkpython. Hey everyone, Michael here. I'm excited to tell you about our latest course.
- 1:38Yes, we just released one a week or two ago, but here's another. This time, it's a nine-hour course
- 1:43called Python for the .NET Developer. The idea is, if you have experience with C# and .NET,
- 1:49would like to get better at Python, we'll take a bunch of common applications from the .NET space
- 1:54and recreate them in Python. For example, we'll take a data-driven web app in ASP.NET and Entity
- 2:00Framework and recreate that in Flask and SQLAlchemy. This means you can take all the concepts and ideas
- 2:05that you know if you're a .NET developer and quickly transition to being an effective Python
- 2:10developer. Are you the sole Python developer at a .NET shop? Maybe your team or co-workers could quickly
- 2:15use their .NET background to get up to speed on Python to make it an important part of your tech stack.
- 2:20There's even a For My Team button. Just click that and enter the number of team members you have,
- 2:25and you'll probably get a discount to boot. I was also just a guest on the excellent .NET
- 2:29Rocks podcast with Carl Franklin and Richard Campbell. If the idea of the Python for .NET
- 2:34developer course intrigues you, just visit .NET Rocks.com? show equals 1665 to hear us discuss this from
- 2:42both sides of the technology fence. So check out the course at talkpython.fm/.NET, D-O-T-N-E-T,
- 2:50and convert those C-sharp skills to Python skills. Now, let's go talk with Steve.
- 2:55Steve, welcome back to Talk Python To Me. Thanks for having me back. It's great to have you here.
- 2:59We're recording on location here at Microsoft Ignite, so a lot of fun to do that at the conference
- 3:05here. Yeah, is this your first time at Ignite? It is my first time at Ignite. How have you found it?
- 3:10I've been a couple of times. I am very surprised at this place, to be honest. So to me, big conferences
- 3:16are PyCon, Microsoft Build is a pretty big conference. This thing is like six times,
- 3:24seven times as large as those. The scale is crazy. This is 30,000 attendees, at least on the first day.
- 3:29I feel like it drops off. I don't think there's 30,000 today. We're on the last day. It's kind of
- 3:34quiet. Yeah, it's way, way more quiet. But yeah, I actually found it really nice. I've made a lot of
- 3:39cool connections and met a lot of people. I've met a lot of Python people even here running to some
- 3:44folks. So I'm finding it to be a cool event. He had an interesting person come up and ask you about
- 3:49your laptop. Oh, yeah, yeah. So it is the mix of the audience. It's not really a developer crowd,
- 3:54right? It is sometimes, it is a developer crowd, but it's also an IT crowd. It's a SharePoint crowd.
- 4:01It's a DevOps crowd. It's a cloud person. There's like all these different,
- 4:04like all the computing IT folks brought together. So I was sitting around actually getting ready for
- 4:09this interview to talk to you. I was taking some notes about what we're going to talk about. And
- 4:13this guy comes up next to me. He's like, hey, that's a cool Surface book you got there. I don't
- 4:17think I've seen that one before. I'm like, it's really cool, but it's a Mac book, not a Surface
- 4:22book or Surface laptop or whatever he called it. So yeah, it's just, it's really funny. And I think that
- 4:27actually is, it's an interesting angle to what we're going to talk about today.
- 4:31Yeah, it's such a different crowd here compared to the Python conferences where we'd normally hang
- 4:36out. I feel like, I feel like I've invited you into my house for this one.
- 4:39Yeah, I've come to visit you this time, not the other way around. That's right. So yeah, I think
- 4:43at PyCon, non-Windows computing or development is pretty common. And here, like, no joke,
- 4:52they were mistaking my Mac for a Windows machine and like, oh, well, I only do C#. I'm like,
- 4:57okay, that's cool. Yeah, I know C# too, but now I'm doing Python over here right now,
- 5:01you know, things like that. And it's cool to be part of these different communities.
- 5:05And it has been really exciting to see the change at Ignite over the years and Build, in fact,
- 5:09because they are very different communities. But the growing Python that's showing up in them,
- 5:14I feel like the first or second time I was at Build and Ignite, which would have been
- 5:192014 or so, about five years ago, people were asking, you know, what's Python? Why are you here?
- 5:25Which is, you know...
- 5:28What are you doing at our conference? Why did you invade it with your open source weirdness?
- 5:31Right, exactly. It's like, what's your angle here? And they were kind of suspicious. And now it's at
- 5:36the point where I actually had someone come up to me yesterday and say, you know, because I was here,
- 5:42because I was actually here and saw everything going on, I now want to learn Python.
- 5:47And that, I mean, I've never heard of that happening at the Microsoft conferences before,
- 5:52but that's really exciting.
- 5:53It's super exciting. Yeah, it is exciting. You know, I don't know, maybe they saw some kind of
- 5:58machine learning presentation or something. They're like, wow, that I thought this was a
- 6:03scripting language. Look what they're doing.
- 6:04Yeah, we had a lot this year. I think two years ago, I was the only Python presentation at the entire
- 6:09conference, which was...
- 6:11There's a lot of presentations at this. That's like a very small percentage, right?
- 6:14There's like, I don't know, we have this huge screen behind us with about eight sessions
- 6:19running in parallel. And that's just this end of the rebroadcasting. There's probably like
- 6:2415 tracks or something crazy going on.
- 6:27Yeah.
- 6:27But no, this year we had like 30 or so sessions about Python. And yeah, ranging a lot of machine
- 6:33learning, a lot of data science, a lot of app development stuff. It's...
- 6:38Yeah.
- 6:38We're covering a lot more angles now and it's really exciting.
- 6:40Yeah, it's super cool. It's not exactly what we're talking about today, but we'll talk about it
- 6:44at some point in the future. You gave a really interesting talk on Python security and plugging
- 6:50that into like operating level security, right?
- 6:53Yeah.
- 6:54Maybe talk really quickly about some of the stuff that's coming there and what you talked
- 6:57about.
- 6:57I kind of like move from project to project that I'm working on. One of the biggest things
- 7:01I've been working on recently is getting auditing hooks, which was PEP 578 into CPython.
- 7:07So that released in 3.8?
- 7:08That released in Python 3.8.
- 7:09Okay.
- 7:10And now it's time for me to go around and teach everyone what you're meant to use them for.
- 7:14Because it's like they don't actually do anything on their own right now. It's just a way of raising
- 7:21low-level events from inside the runtime. So you'll get notifications from the socket module every
- 7:27time it connects to a socket or every time a file gets opened, every time Ctypes gets used,
- 7:32all of the stuff that you really want to know is going on, but Python doesn't really give you a
- 7:37way to see it. And so the security applications of that are essentially logging. You want to collect
- 7:42all that information. And as I said, in some variants of the talk, build a haystack of every
- 7:49single event so that when you figure out there's a needle in there, which is someone attacking your
- 7:54systems, then you've got a chance of figuring out what they were doing.
- 7:56At least you have a record of it. It's not just like, well, it's hacked into, nobody knows why.
- 8:01Right. It's like, oh, I know we got hacked because people are buying our customer database off the
- 8:05dark web. It's like, yeah. And honestly, I think a lot of customers find out they were hacked by
- 8:09saying, I only gave this email address to this, you know, they do like the plus thing,
- 8:15like such and such plus, right? Site name or whatever at Gmail.
- 8:20Or you get one of those emails. It's like, I know your password and here it is.
- 8:24You're like, how did they get that?
- 8:25Yeah. Yeah. Well, that speaks to a whole nother level of badness.
- 8:29You know, just, I recently had to like sign into a bunch of a bank accounts. I'm trying
- 8:34to consolidate just some like retirement, boring stuff. But I finally broke down and like said,
- 8:37I have to do this. So here I go. And I tried to log into the bank. There was some workflow
- 8:42where I created an account and I used a 30 character randomly generated password. And I couldn't log in
- 8:47again. And I kept getting like an error too long sort of thing. And they were saying, well,
- 8:52the password has to be 16 characters or less. And you know, the hash of a password is always the
- 8:58same size, no matter how large the input. So what are they doing with that password? If they care
- 9:03about the length of it? I'm not going to speculate on that one, but it's not, it's probably not good.
- 9:08That may not be where you want to consolidate all of your retirement savings.
- 9:10I was trying to get away from that place. So I feel all right about that. All right. So,
- 9:13but what you were talking about with the Python stuff is there's really interesting hooks that you can
- 9:18plug into for like compile or evaluate or like execute code. There's a bunch of neat stuff that
- 9:25you got going on, right? Yeah. And that's one of the really scary things that Python can do that,
- 9:29that most other tools installed on your system can't do is you can obfuscate the command line.
- 9:33And so you can pass in the example I showed was like a big fat base 64 string wrapped up in a little
- 9:39bit of decoding and eval to dynamically essentially decrypt code and run it without anyone actually being
- 9:47able to see what it is. And so you, you don't know what it's doing until you go through and decrypt it.
- 9:50The sample I showed then went off and downloaded more code off the internet and decrypted that.
- 9:55Yeah. Cause once it started, then, then it's trouble.
- 9:57Yeah. And so being able to hook the compile event, every time a bit of Python code gets exact or evaled,
- 10:02you, you see what's going on and it's really hard. People have tried to, you know, sandbox Python
- 10:07and just take those things out. And it turns out that doesn't work well firstly, because you need them
- 10:12for a variety of things in the, in the language and standard library. And it's, there are other
- 10:16ways to fight to work around that and to still compile code. So this way you don't block it hard,
- 10:23but you get to see everything that goes through it. And then if something bad does happen, at least
- 10:27you know about it.
- 10:27Yeah. It's, it looks really positive and you know, I don't want to talk more about it cause
- 10:31that's not really the topic of the show, but there was,
- 10:32Let's do that one later.
- 10:33Yeah. We'll do that as another show, but that's what you were here talking about. And the audience
- 10:36was full, right? Like people were really interested in this.
- 10:38Yeah. There's a lot more security minded people here. I did run around and do a quick survey
- 10:44or just a quick chat with everyone who was attending and it was a really interesting,
- 10:48What was the mix?
- 10:48Diverse crowd. It was equal parts developers, security administrator, IT management. it was
- 10:55a pretty good spread across all the roles that would be interested in, in managing where and how
- 11:01Python is used in their setup.
- 11:02Yeah. Yeah. The people asking questions afterwards were like, I'm not a developer,
- 11:06but I have to sort of oversee the execution and protection of this stuff and so on. So help me,
- 11:10help me understand how to do that with Python. That's pretty cool. All right. Now let's talk
- 11:15about Python and windows because it's okay. Actually. Yeah. It's okay. Yeah. Actually. Yeah.
- 11:20That's awesome. You know, when I go to a lot of conferences and like, especially I think PyCon
- 11:26falls under this banner, you walk in and it does feel like most people are on some kind of Mac or maybe
- 11:35running Linux. Like there's some windows folks there, there's, you know, some surfaces and whatnot,
- 11:40but it doesn't seem to be very, doesn't seem to be the majority. Does it?
- 11:44There are more and more surfaces, which we're very excited about, but yeah, the, there is always an
- 11:49army of glowing fruit staring back at you while you're speaking to that crowd.
- 11:53That's right. They just stand out mocking you there with a little bite. Yeah. So it feels like
- 11:59it can feel like to a lot of Python developers and especially, I think it's the most relevant
- 12:04audience is the people building Python packages, right?
- 12:07Yeah. Yeah. So it is certainly the most popular platform that, that and Linux for, for the people
- 12:14that are building the open source stuff that we know and love and rely on. And I think what's really
- 12:18interesting is that that's about the only data point that really looks like that. It's a bit of
- 12:23conference bias, I think as we see it ignite as well, it's biased in the other way. Yeah. And just
- 12:29through that kind of selected audience, you're going to see a certain set of people. But the problem with
- 12:35that and the problem with kind of all, you know, diversity type topics is if that's all you see,
- 12:40and that's what you believe reflects reality. Right, right. How would you know otherwise?
- 12:44Exactly. It's not exactly the, you know, the same thing, but Scott Hanselman also from Microsoft has
- 12:50a really interesting saying, he did a blog post on dark matter developers. Are you familiar with this
- 12:54idea? Yeah. Yeah. Yeah. It's that there's a whole bunch of folks out there who write code,
- 12:59they go to work, maybe they work at some big company. They're not so passionate that they're on
- 13:03Twitter all the time, right? They're not going to conferences or the meetups. They just, you know,
- 13:07they're happy programming, they do their job and they go home and they're not blogging, tweeting,
- 13:11podcasting about it. And that world probably looks a little bit different, right? Like what those people
- 13:17need, but it's still, they're a really important consumer and user of programming languages.
- 13:21Yeah, absolutely. And I've met quite a few of those developers in through visiting like any of the big
- 13:28companies or financial institutes at like in New York, I've gotten to meet some of those guys and
- 13:33it's like, yeah, they show up in a suit and then they go home and they stop thinking about coding
- 13:37completely for the night. That's fine. Right. Like if that's one of those, it sounds great. I wish I
- 13:42could stop thinking about coding at night. I know exactly. Exactly. So let's talk about it. So it feels like
- 13:48conference reality is like, I don't know, 70% Mac, 15% Linux, 15% Windows. But then in your presentation
- 13:57you did at PyCon, you talked about, well, that might be what the like survey around here is, but let's just
- 14:02look at the numbers, right? The real numbers. Yeah. So what are some of the numbers? Yeah. So I went and
- 14:08tracked down, there's a few data sources that everyone has access to that I went and looked at. And there's a few
- 14:13that I've managed to speak to some people individually and get some numbers out.
- 14:18PyPI is a great source of who's downloading various packages. And so I pulled that one up and
- 14:24checked out, checked out a few packages. There's no easy way to kind of query the whole thing. And it
- 14:30doesn't, it doesn't really make sense to do that. It doesn't make any sense to measure like PyWin32 or
- 14:35something like that, right? Right. PyWin32 is, is, doesn't get installed very often on Mac,
- 14:39oddly enough. If it only badly, right? So, so, you know, I tried to look at the ones that get
- 14:44installed everywhere in it and it turned out that it was roughly, you know, majority Linux and,
- 14:49and roughly equal Windows and Mac, which already is saying, okay, this is different from the PyCon
- 14:53crowd. Yeah. And interestingly, since then we've done some more analysis on the PyPI data and found
- 15:00that there's a few packages that have long lists of dependencies that may be skewing those numbers
- 15:06even further. Okay. In favor of Linux. So, so there's one particular package that, that I won't name,
- 15:13but it's, it's one of the major cloud providers tools. All right. So if you grab it and then it's
- 15:18going to grab 20 other things. So that counts as like 20 downloads from Linux or something like that.
- 15:22Yeah. That counts as, well, it's going to count as a Linux download for those. And we found that that
- 15:27particular package had a massive, massive spike on Linux for some reason. And I don't think anyone's dug
- 15:32into exactly why, but it's like in the tens of thousands of downloads a day, well beyond where
- 15:39any other reasonable package should be. Right. Okay. So those numbers are still skewed, but,
- 15:43but they are saying it's majority Linux, whereas a conference is not majority Linux. I had a chat with
- 15:48the, the Anaconda folks to see what they could tell me about people downloading from Condor.
- 15:52Yeah. I feel like they're a little more enterprise focused and that might have a different crowd.
- 15:56They're a little more enterprise focused as well. You see the percentage of windows
- 16:00downloads increasing there. So it's roughly double what it is for Mac and Linux is still
- 16:04about half of the overall downloads. Okay.
- 16:07The PSF survey. And, and we've had two of these now, and I believe that there's one going on right
- 16:12now. I think that's probably be over by the time we finish the time we release it. So it's a little
- 16:17bit, I wish I could, we could encourage people to take it, but it'll be great to look at the 2019
- 16:21results. I'm, I suspect we'll see some interesting trends.
- 16:24Yeah. So, so the interesting thing that happened with that is they changed the question slightly
- 16:28between the 2017 and the 2018 one. So in 2017, they didn't actually ask the question and they
- 16:33looked at people's huge user agents to figure out which OS they were coming from. Right. Right.
- 16:39And that one showed you half of all the survey respondents were on windows and fewer on Mac,
- 16:45fewer on Linux. And then, then there was a big gap, which some of us speculated it's probably Android
- 16:50in iOS phones. Yeah. Cause you can take the survey on whatever you're on, but half the people
- 16:55responding were on windows, which means that's kind of like a max level, I feel like, but then the
- 17:02following year they asked the question again and, but this time they let you choose multiple responses
- 17:06and they say, which ones you develop for. And so the interesting, the only thing that really changed
- 17:10between the two sets of data is that windows are still 50% and Linux went from about 10% up to 60%.
- 17:19Wow. And so people are devving on windows, but pushing to the cloud on, on Linux.
- 17:24My hypothesis, and we haven't checked it. And hopefully the current survey is going to
- 17:27help clarify this is people develop on windows and deploy on Linux and, or they work on windows.
- 17:35Yeah. Deploy to Linux. And so you already have a much bigger chunk of windows showing up there
- 17:39than you ever see at a conference.
- 17:40How much do you think Docker influences this? Because Docker is like, I feel like it would
- 17:47overcount the Linux side of things. Cause you so often recreate these images and they reinstall
- 17:53and reinstall, you know, like...
- 17:54Definitely. But virtual environments are going to be much the same thing. So I think there's,
- 17:58there's a lot of repetition, but, but I guess virtual environments are now cached for things
- 18:03like PyPI. So you're not actually going to count the download again.
- 18:06Yeah. Yeah. Yeah. Yeah. But a fresh, like a fresh change of like a low level part of a Docker image
- 18:10might as well, or CI as well, but CI is probably cached. I don't know.
- 18:14Ultimately the point that, that I eventually got to with all these numbers is we don't have a good
- 18:20answer for how many people are using this. Like you go and look at, at the editors that we also
- 18:24have numbers for us, a VS Code, PyCharm and their majority windows, either slim or significant
- 18:30majority windows and smaller Mac, very, very little Linux. And about all we can really say is that
- 18:36the numbers don't line up. They definitely don't line up with what we see at a conference. And when
- 18:41you walk around PyCon and you come away going, literally everyone is running on a Mac. Then all we
- 18:48can say is we know that that's not true. Right.
- 18:50So I feel like conservatively, probably half the Python community, half the Python user base
- 18:56is running on windows either for development and deployment or just for development, then deploying
- 19:01to another platform. Sure. And that's, so the other stat that I pulled out just for fun, because it's a
- 19:05big number, but is obviously biased. So the Python.org downloads, which is mostly where the,
- 19:11mostly where windows developers will get their Python from. And we see that in the stats that's,
- 19:16that is vast majority windows, but the number it's, I ran some of the analysis for one month,
- 19:22uh, about, about a year ago now. And there was 20 million unique downloaders in that month,
- 19:28which is my windows for windows. Yeah. And most estimates of the size of the Python community,
- 19:34like five to 6 million developers. And we got 20 million downloads for windows in that month.
- 19:41So how interesting. So we don't know the exact numbers, but I think we can say that it's certainly
- 19:47not a minority of the Python community. I would, I'd estimate it's about half, maybe more. Yeah. And
- 19:53it's certainly a big number. Yeah. And that's about all I'm prepared to say concretely. Yeah. Yeah.
- 19:58Sure. And so, I mean, maybe one of this, the takeaways from this section is we need to treat the windows
- 20:07dev story importantly in the Python community because a lot of people are doing that and they're either
- 20:12having a good experience and liking Python more or a bad experience and not feeling welcome.
- 20:17Right. And so the thing that concerned me out of that is where, where are, like, where are these
- 20:22developers at our conferences? Yeah. We have all of these Python conferences all the time and, and the
- 20:28numbers vary, but there's, there is nowhere near a representative number of windows devs coming to our
- 20:33Python conferences. And there's also not a representative amount of kind of pain and suffering
- 20:39that you hear online. I mean, I, this is my area. So I watched the Twitter feed for, you know,
- 20:44Python and windows and, and there's a lot of pain out there for a variety of reasons. and so I just
- 20:50wonder how much is people try and get started using Python on windows and give up or they just don't feel
- 20:58welcome because things are painful and it seems like they're just not, you know, no one's aware
- 21:03of them. No one sees them. No one knows they're there. Yeah.
- 21:05This portion of talk Python to me is brought to you by Linode. Whether you're working on a personal
- 21:12project or managing your enterprise's infrastructure, Linode has the pricing support and scale that you
- 21:18need to take your project to the next level with 11 data centers worldwide, including their newest
- 21:23data center in Sydney, Australia, enterprise grade hardware, S3 compatible storage, and the next
- 21:29generation network. Linode delivers the performance that you expect at a price that you don't get
- 21:35started on the node today with a $20 credit and you get access to native SSD storage, a 40 gigabit
- 21:40network industry leading processors, their revamped cloud manager at cloud.linode.com root access to your
- 21:47server along with their newest API and a Python CLI. Just visit talkpython.fm/Linode when creating
- 21:54a new Linode account and you'll automatically get $20 credit for your next project. Oh, and one last
- 21:59thing they're hiring. Go to linode.com slash careers to find out more. Let them know that we sent you.
- 22:07How many of those do you think are students? I do have some slightly more demographic data from the
- 22:13Python in the Windows store distribution. So that gives me a little bit more information. There's some
- 22:18age banding and some regional information. And that does certainly make it look like the majority of
- 22:25people installing Python on Windows are college students in the US and China primarily. Okay. Oh,
- 22:32that's pretty interesting. Yeah. Okay. Well, and it might not be that they're developing on it. They
- 22:36might just need it to run something as well. They may just need it to run, but given how new the
- 22:42Windows store distribution is, it's kind of unlikely that you'll find it unless you're looking for it.
- 22:46Right. Okay. Yeah. So I guess the story is here's the numbers that you're giving us.
- 22:51Right. We've got a lot of different sources and they all seem to point at generally the same trend.
- 22:57Now what? What do we do about that? Yeah. Well, and so I was giving a conference talk,
- 23:02right? So I had to speak to the people in the room. There's only so much value in getting up in front
- 23:08of a crowd of people and telling them that someone else has to do something. Yeah. I don't like doing
- 23:13that. So I was like, okay, what pieces can the people here help with? Because it's no one's fault,
- 23:20really. It's like when a conference doesn't reflect the general population for its area,
- 23:27it's really hard to say whose fault that is, but I think it's easier to say, knowing who you are,
- 23:35who's here, here are things you can do that will be net positive.
- 23:38Right.
- 23:39So PyCon, as we said, it's a lot of library developers, a lot of enthusiasts, it's people
- 23:43writing codes, people publishing code.
- 23:45People who are getting paid to do Python development already. So they're in a different demographic and
- 23:50whatnot to some degree as well, right?
- 23:52Right. And so from that, I'm like, well, okay, these are the people who are potentially writing
- 23:57the libraries that just grate a bit on Windows. Like for one little reason don't work well for
- 24:03this Windows crowd and maybe, you know, contributing to that old Python community doesn't really think
- 24:09about Windows. And so I built the talk around that and kind of went through some of the major
- 24:14kind of cross-platform mistakes or assumptions that I see people make that don't actually translate
- 24:21cross-platform well. Python already does a fantastic job of, you know, hiding most of that.
- 24:25Right.
- 24:26And then there's some things that bleed through that, that can, you know, if you're not aware
- 24:31of them, then you are going to make code that doesn't work well on other platforms.
- 24:35And the best part about it all is when I started going through those and find, and, you know,
- 24:40planning out the right way to do things, turned out they're all just best practices anyway.
- 24:43Right.
- 24:44And they make you code better on all platforms.
- 24:46Right.
- 24:46Like don't treat paths as strings, treat them as, you know.
- 24:50Right. Treat them as path objects.
- 24:52Yeah, exactly.
- 24:52So yeah, that's, that's one of the big ones because most people are aware, you know, Python,
- 24:58not Python, Windows uses backslashes to separate path segments and POSIX uses forward slashes.
- 25:03And so that's kind of an immediate difference where if you've written your code using the
- 25:08string functions and it's all, you know, string dot split forward slash, that doesn't split
- 25:12anything on Windows.
- 25:13Yeah.
- 25:13That's a bad time.
- 25:14Let's start the story of like what we can do on Windows, which you say is really is kind
- 25:21of like actually just best practices for Python code anyway.
- 25:24But, you know, we got to get started by having Python on Windows.
- 25:27Yeah.
- 25:27Right.
- 25:28And you've done some interesting work there.
- 25:30Right.
- 25:30And the fun thing is this, this actually happened between two of the times I gave this talk.
- 25:35And so I had to go back and, and, and say, you know, you assume that this is true.
- 25:40And yeah, and now you're right because I fixed it in between.
- 25:43So, so yeah.
- 25:45I fixed your assumption.
- 25:46People have, have kind of got the hang of installing Python from the Python.org installer.
- 25:51And one of the big differences that that has from, if you install it on Mac or Linux is it
- 25:57doesn't put Python on path by default.
- 25:59And there's a checkbox, but you got to check it and you got to know that it matters.
- 26:03There's a checkbox, which I really don't like.
- 26:05Like I put that there under protest.
- 26:07Okay.
- 26:07And I don't like it because when you put a directory on path in windows, it's not the
- 26:11same thing as putting a symlink in kind of an already shared directory.
- 26:15So you do that on, on Linux and, you know, you put it in the user's bin directory and then
- 26:21it just shows up.
- 26:22And the only thing that they get access to is Python.
- 26:24But on windows, when you do this, you're injecting an entire path with every single file in that
- 26:29directory.
- 26:30All the executable stuff that's hanging out with Python.exe, right?
- 26:34All the dynamic libraries.
- 26:36So if some other application tries to load the Python DLL, it might find the one that
- 26:41you put on path because that's how the resolution works.
- 26:44Right, right, right.
- 26:44And maybe that's like version one of, I don't know, some D library and they are actually looking
- 26:52for version two.
- 26:53And of course they're compiled against the header for version two.
- 26:55So they are going to like hard crash because that's not going to line up and whatnot.
- 26:59Right.
- 27:00It's a big problem.
- 27:01Yeah, exactly.
- 27:01So, so I, I'm not a fan of putting Python on path.
- 27:04That said, my, my fix for this, which I'll get to is I'm, I'm very happy with, but it
- 27:09also doesn't come as like a Python three dot XE or Python three dot seven dot XE.
- 27:13It would, it would just be a Python, which goes against all of the instructions that are out
- 27:17there on how to run it.
- 27:18Right.
- 27:18All the getting started tutorials say type Python three, this pip three, that probably sources
- 27:24thrown in there or dot.
- 27:25Oh yeah.
- 27:25Source activate.
- 27:26Yeah.
- 27:26There's just all these kind of little rough differences.
- 27:29And the first few times I gave the talk, I pointed those out.
- 27:33The last time I gave the talk, I got to actually say, Hey, there's a new package for this.
- 27:37There's a new installer for Python, which comes through the Microsoft store.
- 27:42It's still released by the Python software foundation.
- 27:45Like it's exactly the same as the one that you get from Python.org.
- 27:48It just comes in different packaging.
- 27:49And the nice thing about this is this one has a more POSIX like system for putting shortcuts
- 27:54on path.
- 27:55Okay.
- 27:56So it already comes with, it has a directory that's already on the user's path that only
- 28:00has essentially symlinks in it.
- 28:02I see.
- 28:02And so in there, I was able to put a Python three, oh, a Python, a Python three and a Python
- 28:08three dot seven or three dot eight shortcut that doesn't have any of the downsides of putting
- 28:13all the other directories on there as well.
- 28:15And so that now makes all of the commands available on windows as well as Mac and Linux in
- 28:21exactly the same way.
- 28:22Yeah.
- 28:22That's such a positive thing.
- 28:24So you can go there and you can now type Python three on windows and it, it means basically
- 28:29the same thing.
- 28:29You don't have to be an admin on the box to install it.
- 28:32Right.
- 28:32Yeah.
- 28:33As long as you can get the store, it just lives on.
- 28:35You probably are not even affecting other users on that window system, right?
- 28:39No.
- 28:39The only impact it may have on other users is if they install Python from the store, then
- 28:44windows will go, oh, I've already got this once.
- 28:46I'll give you the same one.
- 28:47Yeah.
- 28:47And, and it still separates everything by user, but it, it does save them the download.
- 28:51Right.
- 28:51Right.
- 28:51But it's not, you're not going to break one of their apps by installing.
- 28:54You can't install anything in their space.
- 28:56They can't install anything in yours.
- 28:57It's a good setup for multi-user Python.
- 29:00That's super cool.
- 29:01Another thing that's worth pointing out is even if you don't do that on windows 10 now, if
- 29:06it's properly updated to the latest and you type Python three, it doesn't say Python not
- 29:11found or Python three not found.
- 29:13Right.
- 29:13Right.
- 29:14That was one of the big benefits of putting it in the store is it made it really easy
- 29:19for the windows team to come around and say, well, what if we just put a shortcut in there?
- 29:24It's like, everyone's been asking for years, you know, can you just put Python in windows?
- 29:27And we figured out the best we could do without taking on a massive maintenance burden, which
- 29:33was, we'll just put a shortcut in there.
- 29:34And so you run Python, you run Python three and it'll bounce you to the store where it's
- 29:39then one click to actually get the Python and Python three.
- 29:42Then you type it again, then you're good.
- 29:43Type again and you're good.
- 29:44And we're actually seeing literally thousands of people a day installing Python through that.
- 29:49And they, they probably maybe didn't even know that that was what they needed to do.
- 29:53They just wanted to run Python.
- 29:54They typed it and said, you don't have it, but click this button and you'll have it.
- 29:56I've recommended it to a few kind of trainers and teachers and they absolutely love it because
- 30:02they can now go into a classroom and say, just type Python three on your machine.
- 30:06See what is it?
- 30:07What happens?
- 30:07And if it pops up with this, click install and now type Python three again.
- 30:11And everyone in the room is ready to go.
- 30:14Yeah.
- 30:14A lot of those training situations as well.
- 30:16Those folks don't have permission to install the wide open MSIs and all sorts of stuff that
- 30:22will like shut down a class.
- 30:25You're like, okay, the first thing we're going to do is install this.
- 30:28We can't install it.
- 30:29Well, this is going to be a real short presentation.
- 30:31Yeah.
- 30:32The next two hours are going to fly by.
- 30:35Exactly.
- 30:36Just, you just have to watch.
- 30:37All right.
- 30:38So I think we kind of started on the first thing is like, how do I run Python?
- 30:43Right?
- 30:44Not, things are not always in the path.
- 30:46The, the path story is, is different.
- 30:48Typing Python three until recently used to be a problem they would run into.
- 30:55People would have to Google about like, well, why does Python three not work?
- 30:58How do I get Python three?
- 30:59It says I have Python installed in like my installed apps, but I type Python three and
- 31:03it doesn't work.
- 31:04So I think people still need to be cognizant of that because even though the fix is now
- 31:10there, it's going to be a while before all the windows machines live in that world.
- 31:15Right?
- 31:15Yeah.
- 31:16It always takes time to roll out new things and hopefully over time as more and more
- 31:20people see it, then we'll see more instructions.
- 31:23I'm really looking forward to people not posting new instructions every day on how to install
- 31:27Python the old way.
- 31:29Yeah.
- 31:30And we start seeing some more, more people posting how to, how to install it the new way.
- 31:34Right.
- 31:35Here's the store.
- 31:35Click it.
- 31:36Yeah.
- 31:36And, and so in an effort to do that, we actually convinced some of the Microsoft documentation
- 31:42team to put our own, how to install Python on windows page up.
- 31:45Okay.
- 31:46So, so I will have to double check the URL, but I think docstopmicrosoft.com slash windows
- 31:51slash Python.
- 31:52We'll get you to some of our getting started with Python on windows page.
- 31:56That's pretty cool.
- 31:57that, you know, we invested in writing up and, and getting good steps and it'll take
- 32:02you all the way through to, oh, you're a student.
- 32:04Here's how to build your first game with Pygame.
- 32:06You're a system admin.
- 32:07Here's how to build, here's how to write a script that'll do like some file scanning.
- 32:11Yeah.
- 32:11So, you know, we're trying to, to move the entire world forward rather than leaving everyone
- 32:17in the, you know, here's how to install Python 3.4 instructions, which I still saw pop up
- 32:23recently.
- 32:23Oh my goodness.
- 32:24Yeah.
- 32:24I definitely looking forward to a world where there's not a bifurcation of every step until
- 32:30you actually get to run in your code is, is what do on Mac and Linux is what do on windows,
- 32:36right?
- 32:36Like another thing that, that varies is pip three, right?
- 32:39Yeah.
- 32:40So pip's always been a little bit better off because it would generate the versioned shortcuts.
- 32:46It's done that for quite a while.
- 32:48One of the downsides of the windows store installation is that you can't, you can only
- 32:56add shortcuts into that directory if you're actually the installer itself.
- 33:00So I have to pre-declare all of those in the package.
- 33:02And it means that when you pip install a package, it can't update those global shortcuts.
- 33:06And so they go into a directory that's not on your path.
- 33:09Pip these days will print a message saying you should add this to your path.
- 33:12And if you do that, then you'll be just fine.
- 33:13Okay.
- 33:14But, but it does mean that most kind of command line tools that you might install with pip,
- 33:19you won't get to through the usual name.
- 33:21Right.
- 33:22Like black or pip x or something like that.
- 33:24Exactly.
- 33:24Okay.
- 33:25And that's always been an issue that's always kind of run into problems here and there on
- 33:29Python.
- 33:29Yeah.
- 33:30And the recommendation for a long time for, for all platforms, in fact, has been to use
- 33:34Python three dash M and the name of that command rather than trying to use where it
- 33:39is.
- 33:40Python knows exactly where it is.
- 33:41Yeah.
- 33:41And the other advantage is if you know, like that's the Python you're working with.
- 33:46So we generally recommend this for pip as well, because if you pip, if you pip install
- 33:51something and then Python try and import it and your path is messed up and this can happen
- 33:56on any OS.
- 33:57It happens on Linux, happens on Mac, happens on Windows.
- 34:00Then you'll go, why can't I import that package?
- 34:02Right.
- 34:03You like, like you type pip instead of pip three and it accidentally goes into Python two
- 34:07because that's earlier or something like that.
- 34:09Right.
- 34:09Yeah.
- 34:09And so we definitely recommend, you know, Python three dash M pip, even for pip.
- 34:14Yeah.
- 34:14Brett Cannon just wrote a big article about that, talking about how we recommend Python
- 34:20three dash M.
- 34:21Yeah.
- 34:21And for all the different things.
- 34:24This portion of talk Python to me is brought to you by brilliant.org.
- 34:27Let me knock something off your holiday to do list.
- 34:30Gifts.
- 34:31Spread the love to your loved ones by gifting them brilliant.
- 34:34This really excites me because it's such a fun way to nurture curiosity, build confidence
- 34:39and develop problem solving skills crucial to school, job interviews or to their career.
- 34:44Brilliant's thought provoking content breaks up the complexities into bite size, understandable
- 34:49chunks that will lead them from curiosity to mastery.
- 34:52Go to talkpython.fm/brilliant and grab a gift subscription to help your loved ones finish
- 34:59their day a little smarter this season.
- 35:01That's talkpython.fm/brilliant or just click the link in the show notes.
- 35:05I'll call out some false assumptions that you had that people often make about writing code.
- 35:12So we touched on this first one a little bit like everyone uses forward slash for path.
- 35:15Yeah.
- 35:16I see this assumption pop up a lot and it normally looks like, you know, using the string functions.
- 35:22So string dot split dot partition and just passing in a forward slash.
- 35:25That works fine as long as, you know, every platform you're on is using forward slashes, but
- 35:30there's plenty that don't.
- 35:31I use the built-in path lib or os.path style to process that, even if I know it's only going to run on a POSIX system
- 35:39because I don't want to have to deal with thinking about that, right?
- 35:42Yeah.
- 35:43As a string.
- 35:43There's a lot of, Python has about five different ways you can do this,
- 35:47but certainly the os.path module is very useful.
- 35:50And the nice thing about that is you can also import POSIX path directly or NT path directly.
- 35:55If you know you need cross-platform behavior, if you like specific platform behavior.
- 35:59Okay.
- 36:00And so I've definitely written code that uses os.path for some things and POSIX path for other things
- 36:05because that's, you know, it's going to look more like a URL or it's going to be sent to a different system.
- 36:09So you have that option there.
- 36:10But really, we have path lib now and we've had path lib since I think Python 3.4.
- 36:17And that's just so much nicer.
- 36:20Yeah.
- 36:20Path lib is really nice.
- 36:21And yeah, but definitely not strings, right?
- 36:23Definitely not strings.
- 36:24Okay.
- 36:25Because I guess the tie back to Windows is right.
- 36:28Like it will break on Windows.
- 36:30You should do it anytime, but it will actually break, not just be less convenient.
- 36:34It will break because if you get a Windows path.
- 36:36And so the thing that Windows makes a little more complicated here is if you give Windows a path that has forward slashes,
- 36:41it will go through and correct it for you most of the time.
- 36:44Yeah.
- 36:45Not all the time, but most of the time it'll correct forward slashes to back slashes.
- 36:48But any path that it gives you or any path that a user gives you is going to have back slashes in it.
- 36:54And you can't split on forward slash then.
- 36:56Yeah.
- 36:56Because you'll always get one element back and that's probably not what you wanted.
- 37:00No, that's not good.
- 37:01Also, route paths are kind of funny, right?
- 37:04Like it could be weird maps or volumes or other stuff, right?
- 37:07Yeah.
- 37:07Not just C colon backslash.
- 37:08It gets very interesting, the kind of range of shortcuts for identifying a drive or amount point.
- 37:14So there's the kind of internal system representation, which for a drive often looks like a GUID.
- 37:20Like it's a globally unique identifier and no one's typing those.
- 37:24So we have a shortcut that's going to be like C colon or D colon.
- 37:27There's SMB shares, which are, you know, backslash, backslash, computer name, backslash to N slay.
- 37:33Which part of this is the root of the drive?
- 37:35It's like if I'm dotting up the directory, how far do I go before I have to stop?
- 37:39Because it varies and it's different.
- 37:42And the Python libraries know how to handle that.
- 37:45We've built that logic in.
- 37:47Yeah.
- 37:47So just don't use strings for paths.
- 37:49Don't use strings for path.
- 37:50Yeah.
- 37:51Thank you.
- 37:51Absolutely.
- 37:52Use pathlib.
- 37:53Speaking of paths, tilde.
- 37:54tilde slash is always good.
- 37:57That gets me home, right?
- 37:57There's no place like tilde slash.
- 37:59No place like tilde slash.
- 38:01Yeah.
- 38:02People love putting their configuration files in tilde slash.
- 38:06Yeah.
- 38:06And, you know, so Windows doesn't have tilde.
- 38:09Like tilde is just a path character.
- 38:11You can put that anywhere you want.
- 38:13And it's just another part of the name.
- 38:15That lives in the working directory.
- 38:17Right.
- 38:17That lives exactly where you are right now.
- 38:19It's where your heart is, not where you want to be.
- 38:21But people do make the, you know, they do very quickly figure out, oh, I should be using the user profile environment variable or figure out the home directory some other way to do that.
- 38:31But even that, depending on what you're planning to use it for, doesn't necessarily line up.
- 38:37Like you see tilde slash, you know, dot and something for a lot of configuration files on Linux.
- 38:44But on Windows, that just gets thrown into the root of the user's directory, which actually has a set of subdirectories for different purposes.
- 38:52And you start digging down, particularly for...
- 38:55Like app data, local app data roaming, all that kind of stuff.
- 38:58And they all have different reasons and different behaviors.
- 39:00So like app data roaming will actually propagate between different machines on a network if that's configured for that.
- 39:08So anything you put there is going to be copied or maybe copied onto a network share and automatically copied down if the user logs in somewhere else, which is really handy.
- 39:16But if you're using it for, you know, 10 gigabytes worth of log files, then everyone's going to be real upset about saturating the network and login taking so long.
- 39:23Yeah, exactly.
- 39:24The domain controller is out of disk space.
- 39:26We don't know why or wherever it gets stored.
- 39:27But the other thing is that's a very hidden directory to users.
- 39:30Like it isn't...
- 39:31It's about as hidden as, you know, a dot file.
- 39:33Yeah.
- 39:34But if you're creating something that you want the user to see and modify, then they have a documents folder for that.
- 39:40And you probably want a subdirectory in that documents folder anyway, just for organizational purposes.
- 39:46And so you start looking at a very different layout from where you would keep all of this stuff on a POSIX-based system.
- 39:52It makes me crazy when every program thinks it's projects folder needs to live in the root of my user directory.
- 39:59Like, yeah.
- 40:00Wouldn't need to be topmost.
- 40:02Come on.
- 40:02Doesn't need to be top.
- 40:03And that doesn't even help on Windows because it's such a pain to get there.
- 40:06Yeah.
- 40:06Because all of the shortcuts go deeper.
- 40:08Yeah.
- 40:09Documents is really easy to get to.
- 40:10Pictures is really easy to get to.
- 40:11Videos is really...
- 40:12That random folder you created is very hard to get to if you don't know how.
- 40:15Gotta use the address bar of the file stuff.
- 40:18Yeah.
- 40:18For sure.
- 40:19So the fix for all the path problems were to use some of the built-in path libraries.
- 40:24What's the fix for this?
- 40:26So this one, the recommendation I have is to use Apters, which is a module made for this purpose.
- 40:32It's slightly opinionated.
- 40:35So you will see, you know, good programs not behaving exactly like it does.
- 40:39But it's a very simple module.
- 40:41It's a single file.
- 40:42So you may even just copy it into your project and keep it around.
- 40:45But it lets you query for a specific kind of purpose.
- 40:49And so you can say, give me the user's data directory.
- 40:51Give me the user's configuration directory.
- 40:53Give me a cache directory.
- 40:54Give me the documents directory.
- 40:55Yeah.
- 40:56I believe it will give you the documents directory.
- 40:59I think that may be one of the ones that's missing.
- 41:01Okay.
- 41:01Well, you could obviously get the home directory and add documents.
- 41:04And that's exactly it.
- 41:05And that one's not too difficult to add in if you find yourself needing that.
- 41:10But it does it cross-platform.
- 41:12So you import the module and you query for a directory.
- 41:15And it will pick depending on what platform you're on and give you a sensible layout that's
- 41:19not going to surprise, not going to upset anyone who's using it.
- 41:22Yeah.
- 41:22That's great.
- 41:23Strings.
- 41:23Strings are also interesting.
- 41:25Well, yeah.
- 41:26Unicode.
- 41:28Unicode.
- 41:29Unicode is the interesting thing.
- 41:30I had this section of my talk got better and better every time I gave it because people
- 41:34came and gave me more context and more information.
- 41:36Yeah.
- 41:37All right.
- 41:37But let me pose you a trivia question here.
- 41:40Which was invented first or which was released first?
- 41:44Windows 1.0 or the Unicode standard?
- 41:47I would initially guess Unicode, but I'm thinking this might not be right.
- 41:51You'd think so.
- 41:52Unicode has been around for a long time.
- 41:54Stuff in quotes.
- 41:55It doesn't seem like that's totally new.
- 41:57It seems like that should have been right at the beginning.
- 41:59It should have been.
- 42:00Unfortunately not.
- 42:01Windows came out first.
- 42:03There were no emojis.
- 42:04That's the problem.
- 42:05Yeah.
- 42:05No one wanted emojis at that point yet.
- 42:08But because Windows came out first, they had to handle internationalization without Unicode,
- 42:12which is why the code page system is there.
- 42:14And there were previous systems that were already using it.
- 42:17So this well predates Unicode regardless.
- 42:20But it was released in Windows.
- 42:22And about six years before Unicode even came out, it was released in Windows.
- 42:25Which means that you have this very ingrained system of code pages and 8-bit character encodings
- 42:32that now you have a compatibility burden.
- 42:35And so when Unicode did come out, then it just wasn't possible to go back and say,
- 42:40well, forget all of that.
- 42:41We're going to switch to Unicode.
- 42:42Because so much of it was at the C level where you pass char pointers.
- 42:46Yeah.
- 42:47The char pointers are the wrong size for Unicode.
- 42:48And so, okay, trivia question number two.
- 42:50Which came first?
- 42:51UTF-8 or UTF-16?
- 42:53You start with a smaller one, right?
- 42:55You start with a smaller one, yeah.
- 42:56UTF-8?
- 42:56Afraid not.
- 42:58UTF-16.
- 42:58In fact, UCS-2.
- 42:59So the two-byte character encoding was the first one.
- 43:02Yeah.
- 43:03And turns out Windows did actually go, oh, we should adopt this because this is now the
- 43:06standard.
- 43:07And that's why the Unicode encoding is two bytes throughout Windows because that was the
- 43:12official standard at the time Windows said, oh, hey, let's do this.
- 43:15And then UTF-8 came, it was proposed like four or five years later.
- 43:19And eventually, and now that's the standard.
- 43:21And I have no doubt that if Windows kind of restarted.
- 43:24It would just be pure UTF-8.
- 43:25It would just be pure UTF-8.
- 43:27Absolutely.
- 43:28You do get some bloat on a number of languages and a number of very important languages to
- 43:33Windows.
- 43:34So arguably, there's a kind of equalization of kind of memory wastage for certain character
- 43:41sets.
- 43:41If you're in English, then yeah, UTF-8 is vastly more efficient.
- 43:44But as soon as you get into kind of many of the Asian languages and some of the European
- 43:50languages, the 16 bits...
- 43:52It takes more bytes to actually do the UTF-8 stuff?
- 43:55You end up with every single character taking four or five UTF-8 bytes.
- 43:58Okay.
- 43:58That can be a lot.
- 44:00Whereas it would only be one or in some cases two UTF-16 words.
- 44:04Yeah.
- 44:04Which averages out to be smaller.
- 44:06So maybe there's a case for either of those.
- 44:08But just for historical reasons, Windows has ended up with UTF-16 as kind of the default
- 44:15choice of Unicode.
- 44:17And there's no real way to go back and undo that at this point without massively disrupting
- 44:22the entire ecosystem.
- 44:23No one's rewriting Windows with breaking changes that big.
- 44:26Yeah.
- 44:27And so what that leads to, as far as Python's concerned, is a kind of fundamental difference
- 44:33in how paths get passed around as strings.
- 44:34Because on POSIX, it's bytes.
- 44:36In the lowest level, it's bytes.
- 44:39And when it comes into Python, then you can keep it as bytes and pass it back out as bytes
- 44:43and kind of make sure that nothing changes and gets disrupted in the way there.
- 44:47And Windows has the APIs for that.
- 44:49But it's doing a silent conversion in the background through the old legacy code page system.
- 44:53Okay.
- 44:53Which can lose data.
- 44:55It can absolutely lose data.
- 44:57And it seems semi-random.
- 45:00This was a big Python 2 problem, was it would do this.
- 45:03And so you get...
- 45:04This is one of the major breaking changes from 2 to 3, honestly, right?
- 45:07Like in terms of the effect that it had.
- 45:11In terms of the...
- 45:11Yeah, in terms of the effect.
- 45:12But it's also one of the most positive ones.
- 45:14Because I heard from many, many students in particular...
- 45:18Sure.
- 45:18...who logged into Windows with their name.
- 45:22And their name is Chinese characters or Korean characters.
- 45:26It's a language that Python 2 could not support.
- 45:30And sometimes they do it on machines where the code page, the legacy support for Windows, can't handle it either.
- 45:36I can't even say my name.
- 45:38Yeah.
- 45:39That's crazy.
- 45:39They couldn't even print their own...
- 45:41It made them feel terrible.
- 45:42Yeah.
- 45:43So I'm...
- 45:44You know, the break for that for Python 3 was painful.
- 45:47But then you have...
- 45:48It was needed.
- 45:48But then you have a handful of other libraries that still use bytes for paths because it's more performant in their context.
- 45:56But it's also going to break these people again, even on Python 3, if you're forcing all the file system stuff to go through this arbitrary encoding.
- 46:04And so the preferred one is to just use string on Windows.
- 46:07Right.
- 46:08Yes.
- 46:08STR.
- 46:09Works great.
- 46:10STR instead of bytes.
- 46:11Yeah.
- 46:12And in fact, it works fine on POSIX as well.
- 46:14We've implemented on that side the conversion for file system stuff to be perfectly round trip.
- 46:19So even if there's characters in paths that, you know, if you converted to text would be corrupt and it would throw exceptions, we actually preserve those and they'll pass back in.
- 46:29So there's a little bit of a performance impact.
- 46:30But...
- 46:32It'd be better to be slow and right than fast and wrong.
- 46:34Absolutely.
- 46:35Absolutely.
- 46:36Nice.
- 46:36And that's a super easy fix, just like use string.
- 46:38Well, it's never quite as easy as just use string.
- 46:42But where it gets real interesting is if you're doing things like reading in a list of files of the file system and writing it out to another file, because you're in control of that encoding.
- 46:51So Python has not and probably will not change the default encoding of a file.
- 46:58So, you know, you open a file to write text to it.
- 47:00What is the default encoding?
- 47:00The default on...
- 47:02The default is the system locale, typically.
- 47:05Okay.
- 47:05Which for most non-Windows users these days is UTF-8.
- 47:09Yeah.
- 47:10And for every Windows user is whatever the legacy encoding is.
- 47:15And this is a backwards compatibility thing.
- 47:17We would love to change it to be UTF-8 by default.
- 47:19But now you can't read in the file that you wrote with the previous version of Python.
- 47:24And that...
- 47:25Yeah, it's tricky.
- 47:25That's just seems...
- 47:26That's a hard sell.
- 47:27It's very disruptive.
- 47:28Very disruptive.
- 47:29And concerning, like, what do you mean my file is corrupted?
- 47:32Yeah.
- 47:32Yeah, that won't feel good.
- 47:34Yeah, and so even opening a file to write to, if you want it in UTF-8, then you should just specify that.
- 47:39I always put UTF-8.
- 47:40I wasn't sure what I'd get if I don't put that, though.
- 47:42Yeah.
- 47:43You will get...
- 47:44It's not entirely random.
- 47:46Yeah, but it's not entirely the same, always.
- 47:48It's not a complete encoding.
- 47:51Okay.
- 47:51So there will be characters that can't be written out in that.
- 47:54All right.
- 47:54Well, let's maybe round this out with one more false assumption here.
- 47:59We're sitting here looking at my very fancy Surface Book Pro.
- 48:03No, I mean MacBook Pro.
- 48:04And I'm a library developer.
- 48:08And maybe I can't test on Windows.
- 48:11Like, I'm sympathetic.
- 48:12Yeah.
- 48:12Like, half of my users are Windows developers.
- 48:15But I can't verify whether my library works or not.
- 48:18Yeah.
- 48:18And I get this one.
- 48:19Like, it's very easy to...
- 48:21Or it's not very easy to get a Windows setup, necessarily, that it's very hard to switch kind of the platform you're used to to another one just for the sake of being able to address all of your users.
- 48:34But at the same time, that's not...
- 48:36That's like kind of drawing the line too close.
- 48:38And it's like, you know, I'm aware of a problem.
- 48:41And I'm aware that I need to solve it.
- 48:43And I think of one solution and that's too hard.
- 48:46And so I stop thinking about it.
- 48:47Yeah, yeah.
- 48:47That's hard.
- 48:48So no.
- 48:48And that's kind of what I see happen occasionally here.
- 48:51And it just, you know, it makes me, you know, just choke up a little bit because I'm like, that's just bad and lazy.
- 48:59Yeah, and so close.
- 49:00And we have so many better options these days.
- 49:02And it's really saying, thanks, but you're not welcome here to like half the users.
- 49:08Absolutely.
- 49:08Yeah.
- 49:09Yeah.
- 49:09And I could get it 10 years ago.
- 49:11Because 10 years ago, we didn't have GitHub.
- 49:15Or if we did have GitHub, we didn't have the reach of GitHub like we do now.
- 49:18Right.
- 49:19Or Azure Pipelines or all the CI.
- 49:21Azure Pipelines.
- 49:22Like I have GitHub Actions.
- 49:24We didn't have all of these things where you can either set up to do it automatically and not need to own the machine yourself.
- 49:30And we didn't have the reach to be able to say, hey, I need help with this.
- 49:34Can someone come and help me test on Windows?
- 49:36Because that's how it always happened, essentially.
- 49:39Honestly, I think the hardest one to, if it's not you, the hardest one to test for is Mac.
- 49:44Yeah.
- 49:45Right?
- 49:45I test none of my stuff on Mac.
- 49:47That's not quite true.
- 49:50But I do it all through CI.
- 49:51Yeah, exactly.
- 49:52But it's tougher to get CI for Mac.
- 49:54It is.
- 49:55Yeah.
- 49:56It is.
- 49:56But Windows and Linux are pretty easy to get that.
- 49:58They're pretty easy.
- 49:59And Azure Pipelines and GitHub Actions both have Windows, Mac, and Linux.
- 50:03And I think at this point, they have multiple choices for all of those.
- 50:07Okay.
- 50:07So you can do like Mojave versus Catalina.
- 50:09I think Windows 7 versus 10 or something.
- 50:12I don't think we're offering Windows 7 as an option on any of those.
- 50:15You don't want to encourage that?
- 50:15The builds actually run on Windows Server.
- 50:17Not even Windows Client.
- 50:18So you do get a choice between Windows Server 2016 and 2019.
- 50:23And choice of like the Visual Studio version, which is primarily, you know, people should
- 50:27just be on the latest for the most part.
- 50:29Python stuff is not that involved in the build tool set to really need to, you know, I must
- 50:34stay on the old one anymore.
- 50:36We made sure that Python works with future builds as well.
- 50:39So you can build for old versions of Python with newer tools now.
- 50:42Yeah.
- 50:43So that's cool.
- 50:43So the options and the opportunities there is really good.
- 50:47And they're all free.
- 50:47Like it doesn't cost anything to just put on your page.
- 50:51I'm looking for someone to help with Windows maintenance.
- 50:53And it doesn't cost anything for an open source project to be on GitHub Actions.
- 50:57Right.
- 50:58And people are probably excited if they're working on Windows.
- 51:01Like, oh, this is a really easy way for me to contribute to this project.
- 51:04Yeah.
- 51:04Right.
- 51:05Like all I got to do is sort of like run the test and just try a few things out.
- 51:08You'll get more contributors because you're not telling them you have to switch to Linux
- 51:12to contribute to my project because you've got the CI running on Linux as well.
- 51:15Right.
- 51:16So it opens up your pool of contributors and it helps with releases.
- 51:19One of the biggest problems we see every time we release an update to Python.
- 51:23So Python 3.8 came out and we're seeing this happen a bit is packages don't have wheels
- 51:28ready.
- 51:28They don't have builds that like they're not actually ready for Python 3.8.
- 51:32And once you've got a CI setup going, which is almost automatic.
- 51:36Yeah.
- 51:36It's almost automatic.
- 51:37As soon as the CI service has that version of Python on there or has a way to get it sooner
- 51:43and, you know, we're working on making that happen faster, then it's very easy to just
- 51:48spin another build and release that.
- 51:50And all of your users are now successful at installing your package.
- 51:53Good advice.
- 51:54So that pretty much wraps it up.
- 51:56You want to give us the quick summary?
- 51:58The quick summary.
- 51:59The checklist.
- 51:59You had a checklist.
- 52:00You don't have to remember all this.
- 52:02Here's the checklist of what you got to do.
- 52:03Yeah.
- 52:04It annoys me when I see people holding their phones up at me while I'm speaking because
- 52:07all of my slides build up.
- 52:08Yeah.
- 52:09And so like there'll be stuff on the slide that's bad and a big red line is about to appear
- 52:12through it and someone's already taking a photo.
- 52:14They're going to share it on social media now.
- 52:15And I'm like, no, no, wait, wait, wait until it gets crossed out.
- 52:19Yeah.
- 52:19So I told everyone to wait for the checklist at the end of the talk because I did want to
- 52:22make this really actionable and really easy for people to follow up.
- 52:25So the things that I would recommend you check just before the next release of your project,
- 52:30anytime you feel like it, does the dash M option work on it?
- 52:33So if you've got a script entry point, can you also start your project running by typing
- 52:38Python 3 dash M name of your project and document it.
- 52:41Tell your users this is how you can use it.
- 52:43Yeah.
- 52:43Are you manipulating paths by hand anywhere?
- 52:45Like, do you have any dot split instead of OS dot path dot split or path lib objects?
- 52:50I like this recommendation because it's, it's just like you should do the thing that's easier
- 52:55and safer and you'll be, you'll be in good shape.
- 52:57Yeah.
- 52:58Do I put configuration in weird places, which, you know, arbitrary paths for storing stuff.
- 53:03It can make a mess, but it can't, you know, you can lose information and make things a
- 53:07little harder to find.
- 53:08Are you still using bytes for strings?
- 53:11If you've gotten out of Python 2 and into Python 3, then there's no need to do that anymore.
- 53:14That was the problem that we were trying to move people off.
- 53:17So feel free to stop, you know, just use the string type.
- 53:20The string type is very optimized for what it does.
- 53:22And do you have, you know, continuous integration tools or collaborators on your project?
- 53:27Like if it's just you on the project and the problem is that you are not representative
- 53:34of your entire audience.
- 53:35No one person can be.
- 53:36Yeah, no matter who you are or what you do.
- 53:37Yeah.
- 53:37No matter who you are, there are people out there who are using your code.
- 53:40Who are doing things differently from you.
- 53:42And with continuous integration tools, GitHub Actions, Azure Pipelines, you can kind of have
- 53:48automated systems that look like more of your users, but just welcoming more people in to
- 53:52contribute and collaborate.
- 53:53Even if it's just, hey, I'll email you when I'm about to do a release.
- 53:58Can you run, you know, your tests on it?
- 54:00And a lot more people are willing to do that than you think.
- 54:04Yeah.
- 54:04All right.
- 54:04Well, it's all good advice.
- 54:06And I definitely think the stats that you laid out are pretty interesting.
- 54:10So thanks.
- 54:11Yeah.
- 54:11Not the world we often see around us, but it's the world as it is.
- 54:15At least as good as the stats can measure from what we're using there.
- 54:19Cool.
- 54:20All right.
- 54:20Well, before we wrap up the show, let me ask you the final two questions.
- 54:22If you're going to write some Python code, what editor do you use?
- 54:25I'm bouncing between editors all the time right now.
- 54:27What's in the orbit that you're hitting?
- 54:29I use Visual Studio until it annoys me.
- 54:32Then I use Visual Studio code until it annoys me.
- 54:34Then I use Notepad 2 until it annoys me.
- 54:36Then I go back to Visual Studio and that's my code.
- 54:39That's the three-body problem, the three-editor problem?
- 54:41The three-editor problem.
- 54:41Yeah.
- 54:42Yeah.
- 54:42Indeed.
- 54:42And then notable PyPI package.
- 54:44Oh.
- 54:45What have you come across lately that's like, oh, this is pretty amazing?
- 54:48Oh, I forgot this question was going to be here, so I hadn't thought about it.
- 54:51Yeah.
- 54:51See, this is like improv too.
- 54:53On the spot.
- 54:54Yeah.
- 54:54What was I?
- 54:55I was playing with something the other day that I really enjoyed.
- 54:58While you're here thinking, I'll tell you about one I found recently that I thought was kind
- 55:00of cool is HTTPX.
- 55:01Oh, yes.
- 55:02Okay.
- 55:03I do like that one.
- 55:04I like it because it's requests compatible, but it also does HTTP2 and async.
- 55:09And then there's also some intermediate, simpler async parallelism built in it.
- 55:13It's a cool one.
- 55:13I've been helping promote that one.
- 55:15It's in its early stages.
- 55:17It is.
- 55:18They're looking for contributors who are interested in the next big HTTP project.
- 55:22So I'm excited about that one.
- 55:24I guess I can't claim it.
- 55:25Yeah, you claim it.
- 55:25Go ahead.
- 55:25I can claim it.
- 55:26Okay.
- 55:26We both like HTTPX.
- 55:28Yeah, it's a good one.
- 55:29Yeah.
- 55:29It is early days and it could use some help, but I like it as well.
- 55:32I think it's got promise.
- 55:32Cool.
- 55:34All right.
- 55:34Well, Steve, final call to action.
- 55:36People are working on their packages or working on their non-Windows machines.
- 55:41What can they do to welcome the Windows people?
- 55:44I think it's literally just that.
- 55:46Like, welcome the Windows people.
- 55:48You know, I gave a few simple things you can do to make them feel welcome, but it really just
- 55:52is.
- 55:52This also works on Windows, or if it doesn't, we want it to.
- 55:56You know, please help.
- 55:57Yeah, they got the checklist.
- 55:58Yep.
- 55:59All right.
- 55:59Well, thanks for being here.
- 56:00Great.
- 56:00Thanks.
- 56:00Bye.
- 56:01Bye.
- 56:01This has been another episode of Talk Python To Me.
- 56:05Our guest on this episode was Steve Dower, and it's been brought to you by Linode and
- 56:09Brilliant.org.
- 56:10Start your next Python project on Linode's state-of-the-art cloud service.
- 56:14Just visit talkpython.fm/Linode, L-I-N-O-D-E.
- 56:19You'll automatically get a $20 credit when you create a new account.
- 56:22Brilliant.org encourages you to give the gift of critical thought and knowledge.
- 56:27Visit talkpython.fm/brilliant and grab a gift subscription to help your loved ones
- 56:32finish their day a little smarter this season.
- 56:34Want to level up your Python?
- 56:36If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
- 56:41Or if you're looking for something more advanced, check out our new Async course that digs into
- 56:46all the different types of Async programming you can do in Python.
- 56:49And of course, if you're interested in more than one of these, be sure to check out our
- 56:53Everything Bundle.
- 56:53It's like a subscription that never expires.
- 56:56Be sure to subscribe to the show.
- 56:57Open your favorite podcatcher and search for Python.
- 57:00We should be right at the top.
- 57:01You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 57:06and the direct RSS feed at /rss on talkpython.fm.
- 57:10This is your host, Michael Kennedy.
- 57:12Thanks so much for listening.
- 57:14I really appreciate it.
- 57:15Now get out there and write some Python code.
- 57:16I'll see you next time.