Transcript
A (0:04)
Hello from Spearfish, South Dakota, it's the Black Hills Information Security Podcast. This is the podcast version of our webcast, so some of the slides we might reference will be missing, but you can find the whole episode on our YouTube page. This is transitioning from Python 2 to Python 3 with Joff Thier. Enjoy.
A (0:29)
Thanks everybody for attending today. So we're going to be talking about. I was struggling with a title for this one, but I ended up landing on pi2k20, which is sort of a nod to, you know, y2k. I know most of you are probably not even that old now, but you know, it's, it's a fairly big transition that we're looking at from Python 2 to Python 3 and I think people have been a little bit resistant and so I want to talk about some of the things that will change and what that's going to look like for you. Jason already said it. Who's this? Jeff Guy, Pen tester, researcher, developer, Black Hills. I am a Sans certified instructor. We've already talked about Security Weekly and the Sans stuff. If you want to go and look up the Automating Information Security with python class, then sans.org has all the things you need there. You can read about the course outline, the syllabus and so forth and learn about the various instructors that teach it. And Mark Baggett is the author of the class and Mark Baggett, myself and Mike Moore are the main individuals that teach the class right now, although we are onboarding some other people.
A (1:45)
So what's our agenda today? Well, first of all, what's happening Linux distros potential impact. Then we're going to talk about the future module with respect to Python 2.7. X. Then we're going to step through a series of slides which talk about the language differences between Python 2 and Python 3. In short, keywords, division, print format, strings, input, string objects, some file handling and some memory saving enhancements. We're going to talk about variable scope a little bit and then that's a lot to take in. So we're going to sort of wrap up, ask summary and questions. Some of you are going to get focused on module differences such as what's happening with urllib 2, urllib 3, urllib and all that mess. I'm not going to dive into that. I'm really going to focus on what it means in the core language that these changes coming up and a little bit of opinion as well. So Python 2 becomes end of life. So what actually changes? Well, first of all, Pep 394 is the Python enhancement proposal that states that the Python command on a Linux System will invoke Python 2 by default. So that's one thing that may change in the future, but may not necessarily change in 2020. It may stay that way and frankly it really is just a symbolic link on the operating system with respect to Linux. The thing that will change is that maintenance releases of Python 2.7 will cease to be released in 2020. Right now, one other thing to note, and this is regard to PEP394. The 394 recommendation is going to be periodically reviewed. This is a cut directly out of the Python documentation, updated when the core development team judges it appropriately. Right at this point in reference, regular maintenance releases will continue until at least 2020. So Pep394 hasn't committed to changing it, but we need to keep our eye on it. Now, what will the Linux distributions do? This is a sort of predictive question. My opinion is in the short term I suspect the nothing. The main barrier for changing the Python symbolic link to Python 3 is going to be breakage of course of third party scripts and packages, right? Classic example would be the print statement in Python 3 which has become a function instead of a built in statement in the language that would immediately break. So avoiding such breakage of third party scripts is precisely the reason PEP recommends that Python continue to refer to Python to for the time being, okay. However, the Linux distributions are free to change that if they want to, so we do need to keep an eye on it. If they do change it, what does it really mean? Well, not a lot. In the Linux world it means that your friendly system administrator, and that might be yourself, does an su and go ahead and relinks the Python command to Python 2 instead of Python 3. So how much do we really care? Well, somewhat because, well, some package update, maybe a software update to Python itself may change that symbolic link back again. So it's really just going to be a maintenance headache for those that are in the systems administration role with respect to Linux distributions that actually make the move. Now how does this affect other operating systems? In the case of OS X, Mac is going to follow a very similar role that one would expect to see in the Linux world. So it'll be the similar thing. You'll have a symbolic link that's pointing to either Python 2 or Python 3 and you may run into that same issue in the case of a Windows installation of Python. It's really up to you because the Windows installation of Python creates Python EE and depending on which version that you install means that you will either be running Python 2 or Python 3. So it's completely up to you, in the case of Windows, how that's gonna look. Now, let's talk about the future module a little bit. In Python 2, future was a statement that allows us to import or integrate features that have not been released in that current version of the language. So a classic example in the Python 2 and Python 3 transition is making our Python 2 scripts forward compatible with Python 3. And in the case of Python 3, if it sees such a forward compatibility statement, such as from double underscore, future double underscore, we call those dunder variables. Typically the double underscore is dunder. That would effectively be ignored in Python 3, but it's going to be processed to change the division behavior or the print function behavior in Python 2.7.x, which is useful because that allows us to tell the Python compiler or interpreter that a particular module needs to be using syntax or semantics that are going to be available in a specified future release. Right? So it's a migration feature. The future statement is a migration feature that allows us to program in, specifically in this example, in Python 3, syntax within a Python 2 script, a very, very useful feature. We're going to dive into that a little bit as we go through the presentation today. Core language keywords so in Python 2, there were 31 exact keywords in the language, and this is the meat and potatoes of the actual interpreter. I used Python on my OSX machine here to illustrate this. You could use Python, a Linux machine, or a KALI distribution or whatever. You're going to see the same thing. Python 3 changed the core language keyword set such that there are now 33 keywords instead of just 31 keywords. What does that mean to us? Well, really, not a lot. The thing that actually changed is that the true and false and the none statements became keywords. In Python 3 and prior, they were not keywords. So not really a big deal there.
![BHIS Podcast: Py2K20 - Transitioning from Python2 to Python3 - Talkin' Bout [Infosec] News cover](/_next/image?url=https%3A%2F%2Fimg.transistor.fm%2FAukI425sRBc3M3UIa9lVng7qjeNeYEQ8BZfzCEXhALs%2Frs%3Afill%3A0%3A0%3A1%2Fw%3A1400%2Fh%3A1400%2Fq%3A60%2Fmb%3A500000%2FaHR0cHM6Ly9pbWct%2FdXBsb2FkLXByb2R1%2FY3Rpb24udHJhbnNp%2Fc3Rvci5mbS8xZTA1%2FZWZhNDcxZGM4ZTFj%2FZGJhMTMwNmYzMmJj%2FZjBkNi5wbmc.jpg&w=1920&q=75)