Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book

Transcript #18: Python 3 has some amazing types and you can now constructively insult your shell!

Return to episode page view on github
Recorded on Monday, Mar 20, 2017.

00:00 Hello and welcome to Python Bytes, Python news and headlines delivered directly to your earbuds.

00:05 I'm Michael Kennedy.

00:07 And I'm Brian Okken.

00:08 We're here to share the Python news with you and basically share the cool stuff that Brian and I found for the week.

00:14 Brian, you know what I think is cool that I can open up, I can basically go to any Python object or module or even function or whatever and just say, "Tell me what is in you." Durr this thing and out pops all of its capabilities, mostly anyway.

00:27 Yeah, I love that. Do you know what our EPL stands for?

00:30 REPL?

00:30 REPL read a vowel print loop. Just the okay, just what you get me in type Python.

00:35 Yeah, that like most of the time now, the only time I open that is to try out something little or to actually to use the dir command.

00:44 You know what, I do do that as well. I'm like, I'm gonna open this up and just do a dir here. Okay, back to work.

00:49 Yeah, exactly. Just to look at the interface for something. So I was excited to see a new project from Laika9m on GitHub called pdir2.

01:00 When you use it, it's p-d-i-r-2 when you're installing it, but when you use it, it's just p-d-i-r.

01:06 It's just a replacement.

01:09 It's cool because it's all colorized and it splits it out and splits it up into one line per item and it pulls the the the doc string out of each item so that you can so you can see that and it's for what I'm using it for when I pull up the REPL it does what it should do automatically and I like it. Yeah it's cool I mean it's kind of like if you typed help a thing but it gives you meaningful stuff even if there's no real help to be had and it'll categorize things like here are all the classes here are all the functions here's the stuff that I have no idea what it is but it's also there so we'll put it over here. And if there's docstrings it'll put the docstrings there for like here's the description of each thing. It's really nice.

01:50 Yeah and it does, it like puts all the dunder functions out of the way so those aren't in the middle of everything too. Yeah yeah those land in the other.

01:58 Yeah anyway it's just it's part of my repertoire now. I'm gonna, I'm never gonna let it go.

02:03 One of the things I would like to ask somebody to do is to help out with the project and convert the readme to whatever that other thing is.

02:13 Restructured?

02:13 Yeah, restructured so that it looks good on PyPI because the readme is in Markdown and PyPI still doesn't like Markdown.

02:22 I wonder, did you look at it on

02:25 No, I haven't.

02:26 Versus the older one. It's worth looking at that one. I have no idea what it'll look like there either but that's the new one. Maybe it understands Markdown, who knows. I would also like to recommend that people pair this with PT Python. Do you know PT Python? I don't. Oh my god, PT Python is awesome. Like I don't use the REPL very much. Everyone knows I love PyCharm and I kind of live there. But when I do go into the REPL, it really annoys me that I need to completely type everything that is there. That it doesn't auto complete, especially when I'm exploring something new, which is like why we said often we go into the REPL.

03:00 Well, PT Python is basically, I think it's a little bit based on Emacs, but it's like a different version of the rebel that has code completion, and a little bit of a UI over the terminal.

03:13 It's really nice.

03:14 So these days, if I want Python, I type PT Python.

03:17 Okay, well, I'll have to check that out.

03:19 And just to let people know I did.

03:20 Okay, so I'll take back that request, because I looked it up on

03:25 And it looks great.

03:26 It even has that animated GIF on there.

03:28 So Oh, yeah.

03:29 little animated gif that shows you how it works which is quite cool. So yeah check out this project it's easy to use. The one thing to notice is you've got a pip install Peter2 versus Peter but then the modules just PDIR right so there's a little bit of a nomenclature funkiness but it is cool.

03:47 You know what else? Go ahead. I just yeah just want people to remember that and And speaking of memory.

03:54 Speaking of memory, absolutely.

03:56 So more, this has happened to me once in my life.

04:01 I have not used these tools to solve it.

04:03 But here's the deal.

04:04 Like suppose that you somehow through probably your fault, but it could have been like a hard drive failure or something.

04:13 Somehow you've lost your source code.

04:16 So there's a guy who was using a source control wrong and wiped away all of his files off of his directory, but he was still had the program running in memory.

04:25 It was a Python program.

04:27 So he used two really interesting packages that I'd never heard of.

04:32 Had you heard of these?

04:33 No, I haven't.

04:34 One of them is Pyricite, like parasite but for Python, P-Y-R-I-C-I-T-E.

04:39 And the other one is uncompile6, because apparently it's one of the few that supports both Python 2 and Python 3, and multiplication is awesome.

04:48 So uncompile6.

04:49 Alright, so the idea is with Pyricite, you can attach to any running Python process.

04:56 And you basically get this REPL like we were talking about, to just explore its memory to see what its values are, you can even like force it to load other scripts and run them.

05:05 You can go to like in memory, like singleton object and like work with its data, all sorts of stuff you can do in real time while it's still running around.

05:17 That's pretty cool.

05:18 Basically what he did is he said, "I'm going to hook up to it with Pyricite.

05:20 I'm going to force the thing to load uncompile and I'm going to call uncompile on itself and get my code back." Wow.

05:27 But mostly the core-

05:28 Does that work?

05:29 It worked.

05:30 Yes, it worked.

05:31 There are people, there's like a whole bunch of people, I get a gist at the bottom of the gist, they're like, "Oh my God, I just had to try this because I couldn't believe it would work.

05:39 Oh, that's so awesome." Yeah, it works.

05:41 I think there's either a video or a little gif that is just like a, that basically shows you how it works if you go to, which that's the coolest takeaway for me in this whole one.

05:51 That's awesome.

05:52 Good job.

05:53 Cool.

05:54 Yeah.

05:55 All right.

05:56 You know what I think?

05:57 You and I were on a mission, right?

05:58 To make sure that Python is modern Python, not legacy Python, right?

06:00 Yes, definitely.

06:01 And I was really surprised.

06:02 They're still adding quite interesting and new data types to Python 3.

06:07 Even stuff that's been around for a little while that I just haven't heard of, because of this show I've learned about the SimpleNamespace as a... wait no that's not it... the NamedTuple class with capitals. But let's get into this. There's an article called "New Interesting Data Types in Python 3" and it just goes through three that I really like. The three types are Types.MappingProxyType, Types.SimpleNamespace, and Typing.NamedTuple. And the MappingProxyType is like really cool.

06:43 It takes like something like a dictionary or it says, I can't think of anything other than dictionary.

06:48 It says it only takes mapping types, but--

06:50 - Yeah, it's really cool, but it's like a read only dictionary basically, right?

06:54 - Yeah, so you take a normal, like maybe a normal dictionary and like if you had an API or something, you wanted to expose that dictionary through the API, you could wrap it in this mapping proxy type and return that.

07:06 And I tried it out and so for instance, One part of your project could use the mapping proxy type version and read everything.

07:14 And the part of your system that still has write access, that is synchronized.

07:20 So it isn't a copy.

07:21 You can, when one part writes to it, it gets updated in the other place too.

07:25 Oh, it's like a view into an existing dictionary.

07:27 Yeah, it's a read-only view.

07:29 Sweet.

07:29 So that's nice.

07:31 And then not too long ago, I started using where I really wanted classes or something.

07:36 And I was using things like tuples or lists where there really should have been something more structured.

07:42 I've been using the lowercase named tuple.

07:45 Right, out of the collections name, the collections module, right?

07:47 Yeah, out of collections.

07:49 And there is this thing called types.simple namespace that uses a similar sort of functionality.

07:58 You can just-- if you define a type to be that type, you can just--

08:03 the parameters, when you instantiate it, those just become elements inside the object.

08:08 It's pretty convenient.

08:09 - Yeah, that's cool.

08:10 So you can do a little more organization.

08:11 And then of course the tuple class is really nice.

08:15 I hadn't been using it.

08:16 I've always just used tuple.

08:18 But I think I'm going to be switching.

08:19 Now one word of caution I suppose, is a lot of these are, they require pretty modern Python.

08:25 Some of the techniques they show require 3.6.1.

08:29 Like 3.6.0 is not enough.

08:31 So just be aware that some of these require pretty new versions. Yeah, and that's I guess it's hard for me to remember because I'm usually trying to stay, I don't go into the in development Python, but I try to use the latest released one. I do as well. You know where that bites me though, is on my digital ocean servers.

08:50 It's running the version of Ubuntu that only has three five, two or something like that.

08:55 So if it's literally a three six feature, I'll put it in my app and I'll ship it like "Oh, it doesn't work. What was I thinking?" Yeah, and I forget that, that 3.5 is really...

09:04 For 3.x, 3.5 is being used more than 3.6 right now.

09:10 Yeah, just because of the distributions, I think.

09:11 In my mind, that's like the minimum bar for 3 stuff is 3.5.

09:15 Yeah, okay.

09:17 But I think these are great things to start adding to your repertoire.

09:20 If you have control over where it's going to run, those are good things.

09:24 Yeah, and some of them come from Python 3.3 or 3.4.

09:26 They're fine.

09:27 There's just a few techniques there that are brand new.

09:29 And what I like about this, one of the things I like about this article is it's pretty short and it gives examples of how to use these pretty concisely.

09:37 So that's good.

09:38 Yeah, very nice.

09:39 Very nice.

09:40 Speaking of how do I use things, wouldn't it be awesome if I could just go to my bash shell and just type "how do I" and type a thing.

09:48 Like I'd like to say, maybe I want to know how to print a stack trace or trace back in Python.

09:53 I could say, "How do I print stack trace Python?" and just type that.

09:57 - Yeah, that'd be cool.

09:57 - It'd be cool if my computer knew that, right?

10:00 Well, it turns out we ran across a project called HowDoI, and if you install HowDoI, if you pip install it, it will give you instant coding and shell answers on the command line.

10:11 So I can say, "How do I connect SQLAlchemy?" And it'll give me the Python code to connect for SQLAlchemy.

10:18 I can say, "How do I Python save dictionary?" That's three words.

10:22 And it'll show me how to use the JSON load S dump functionality right there in the command line.

10:29 Now, sometimes it gives me like a stupid answer.

10:30 Like if you type that, how do I Python save?

10:33 How do I Python load JSON, it just shows you JSON, which is stupid, but you can do a dash a and it'll give you all the answers it's found on the internet related to that.

10:43 Usually somewhere in that list is something decent.

10:46 It has some sources like stack overflow, and I don't know where they all come from, but they're all over the place.

10:50 It's cool.

10:51 I can say how do I debug Python, it'll show me the PDB commands.

10:55 I can say how do I change my path in macOS, it'll show me how to do that assuming I'm running bash, things like that.

11:00 Okay, I'm going to try it out.

11:02 Yeah, how do I put a worm on a hook?

11:05 Exactly.

11:06 Yeah, it doesn't work.

11:08 Yeah, it's got to be something technical I think.

11:11 So the other, there's another one that I want to point out that I thought was really funny but actually it's kind of useful.

11:16 Oh, what's that?

11:17 It starts with a command.

11:18 It starts, it actually starts with a cartoon.

11:21 And basically the idea is if you type in a command that you think you know on the shell, but you get it wrong, you can curse at your shell and it will potentially fix it for you.

11:30 Yeah, I love this.

11:31 So this thing is called the F. I'm not going to complete it so we can keep our clean rating in iTunes, but the link is in the show notes.

11:38 And basically you type that after you've made a mistake on the shell and it goes, oh, you probably meant this.

11:43 Were you trying to do this git checkout branch thing?

11:45 You did a little bit wrong.

11:46 The F?

11:47 Oh, here's the command.

11:48 And it'll just automatically fix it for you.

11:50 It's beautiful.

11:50 Yeah, nice.

11:51 So plus you get a little--

11:53 yeah, you get to let some frustration out on the thing, right?

11:55 Yeah.

11:56 All right, what you got for us?

11:58 What's next?

11:58 Oh, yeah, I got to go back to that tab.

12:00 We have a-- yeah, we're at a listener--

12:04 so it just seems like we just did the last episode.

12:08 Just a few days ago.

12:09 How's that work?

12:10 That we had a listener commented on the last episode.

12:14 Last episode, we did mention some feedback from a listener about async speeding up their some work.

12:22 And we have another one from a comment this time.

12:24 And this is a project that a listener shared with us.

12:28 And we've got a link in the show notes.

12:30 But it's a project called PyMarsis.

12:33 And I wasn't familiar with eMarsis.

12:37 It doesn't really matter.

12:38 But it's a cloud-based CRM.

12:41 And it's a Python interface.

12:43 But I'll just read this.

12:44 The gist of it is it sped it up.

12:45 And this is from Diego.

12:47 Thanks Diego. Another awesome episode. Thanks Michael and Brian.

12:50 And if you say that we do something awesome, we'll totally put you on the show.

12:54 Okay, about AsyncIO being awesome. I had my own experience.

12:58 I had to send information to about a hundred...

13:01 information about hundreds of thousands of users to a CRM through their public API daily.

13:07 And with synchronous stuff, it would have taken 50 hours a day, which you can't do that. And they added Async And it went down to 20 minutes.

13:18 So that's 150 times faster, which is awesome.

13:21 Yeah, they were using requests before.

13:24 And in order to update their CRM, it took 50 hours per day problem.

13:28 So they switched to the AIO HTTP client stuff that has async and await and 20 minutes.

13:35 In fact, he told us an interesting story.

13:37 He said, the first time I ran it, it like opened so many connections that it crashed his Mac.

13:42 And so he actually had to implement a semaphore limiting system, which is pretty cool.

13:47 Yeah, and I did like that he added that, that he added the semaphores.

13:50 But the GitHub link that he put up, I didn't see any semaphore usage in there.

13:54 So I've also in our show notes linked another article that talks about using asynchronous I/O with semaphores to limit how many connections you're making.

14:03 Yeah, no, thanks, Diego, for putting that up there.

14:06 Anybody who wants to have a comment on the show, you can contact us on Twitter where we're @pythonbytes.

14:10 But also every episode has a discuss section at the end.

14:15 So if you want to talk about an episode, share a link, or whatever, drop in there.

14:18 So what's the link for this episode?


14:21 Yeah, yeah, there you go.

14:22 Cool.

14:23 Yeah, I made it super easy to find.

14:25 And do you know what would be super easy, is if somebody would make an easy way for me to do a pyramid installation.

14:31 That's right.

14:32 So the way I made that /18 work-- and you can still go to /episode/list or whatever--

14:39 is I use constraints in the routing infrastructure.

14:42 And so one of the things that I've been doing a lot of work with lately is with building pyramid web apps and trying to really help people jumpstart what they're up to, right?

14:52 Like I can go to pyramid and create a web app and I get basically a web app that runs and here's the view function and here's a template.

15:00 Go, go write the web app from scratch.

15:03 And I kind of wanted to help the world not start from scratch, but start from near the end.

15:09 So I've been doing a lot with cookie cutter, more on that later, but I decided to create a cookie cutter template that is an opinionated cookie cutter template for creating pyramid web apps that have most of what you need pre-built and pre-configured and factored the way you would for a large professional app, not for like a one file starter thing.

15:28 - Yeah, that's great.

15:29 - So I created a cookie cutter thing called cookie cutter dash pyramids dash dash talk Python starter.

15:33 And so this came out of my Python for entrepreneurs course, but you don't have to have anything to do with that to play with this template.

15:38 So what you do is it comes out with like, when you just say create the website, it'll create like a shared layout.

15:44 So there's one place where all your general navigation and look and feel goes.

15:48 It has handlers for class management.

15:53 It has like secure user management using things like passlib and other techniques, bootstrap, logbook, rollbar integration, MailChimp integration, outbound email integration, power for static file management, all just the list goes on and on.

16:06 But it's very much closer to where you need to be for a professional pyramid app to get started in my opinion, rather than like, basically, here's one file now create the whole thing from scratch.

16:18 So people want to check that out.

16:19 That's on GitHub, you can just cookie cutter space the GitHub URL and you're off to the races.

16:24 It's a little bit more documentation.

16:25 I'm going to work on that this week, but it's really close.

16:28 But it's a good start.

16:29 I'm actually pretty excited about it.

16:31 And you've got one, your course is one of the very few that I've seen that really teaches people how to do Pyramid as well.

16:38 Yeah, thanks.

16:39 Yeah, it's definitely one of the few ones on Pyramid, which is great.

16:41 So here's like one more resource.

16:43 Basically this is going to be part of the end of that course.

16:46 And you know, the first time I heard about Cookie Cutter, I really kind of thought it was a little silly, but it's actually turning out to be quite a useful tool for a lot of spaces.

16:56 Yeah, I definitely, yeah, the more I use it, the more I like it.

16:59 So I've definitely been putting some effort into it.

17:02 It's great.

17:03 Well, that's the end of our six.

17:04 So do you have anything to share with us, Michael?

17:07 No, nothing.

17:08 Nothing other than this template thing.

17:10 That's really all I have to share.

17:11 I've been just cranking on my classes.

17:13 I hear that you're probably still writing on your book.

17:16 That's getting close, though, isn't it?

17:18 Yeah, it is.

17:18 It's getting a lot closer.

17:19 And I wish it was closer than it is.

17:21 But I've got a whole bunch of-- actually, I'm kind of overwhelmed with both work and with gratitude that I've had a lot of great people, incredible programmers and good writers helped me out with technical reviews on the first four chapters and a lot of great feedback.

17:38 And now I got to go rewrite everything.

17:39 Thanks a lot, guys.

17:40 - Thanks a lot.

17:42 No, that's awesome.

17:43 Yeah, I'm looking forward to the day where we can announce your book on here.

17:45 That'd be great.

17:46 Any day now with that book, huh?

17:47 - Any, hopefully we, the goal still is to have something to sell by PyCon.

17:52 - Beautiful.

17:53 All right, well, thanks, Brian, for sharing your news and thank you everyone for listening.

17:58 We'll catch you next week.

17:59 - All right, thank you.

18:00 Thank you for listening to Python Bytes.

18:04 Follow the show on Twitter via @PythonBytes, that's Python Bytes as in B-Y-T-E-S.

18:09 And get the full show notes at

18:13 If you have a news item you want featured, just visit and send it our way.

18:17 We're always on the lookout for sharing something cool.

18:20 On behalf of myself and Brian Aukin, this is Michael Kennedy.

18:23 Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page