Hello, and welcome to Python Bytes, where we deliver Python news and headlines directly
to your earbuds.
This is episode 26, recorded May 16, 2017.
I'm Michael Kennedy.
And I'm Brian Okken.
And we're here to deliver a bunch of cool news around the Python community.
But before we do, I'd like to say thanks, Brian.
I'd like to say thanks to Rollbar, because once again, they're sponsoring this episode.
Yay, Rollbar.
So they're going to be at PyCon, so be sure to drop by their booth and tell them that
we sent you.
All right.
Let's talk about the terminal.
Yeah.
When I think of command line interface, I mean, I use like the REPL and other terminal interfaces.
But most of the time when I'm writing applications that I think of as command line, they just
have, you can launch them from the command line with flags and stuff like that.
But if you wanted to do an interactive, like an interactive terminal application, like a
REPL or something, I don't know how to do that.
And this is, I ran across this two-part series article, a two-part series.
And the first part was just actually talking about, and this is on opensource.com.
And the first article talks about four different applications that have good interface characteristics.
And it started with the MySQL interface and the Python REPL, which were good, but both could
be better.
And the author talked about BPython as a adds auto-completion to Python.
Oh, BPython.
Interesting.
I've never heard of BPython.
I use PTpython.
Well, the article also mentions PTpython.
So I was going to try both of them out and see which one I liked better.
Oh, okay.
You'll have to give us a report.
Yeah.
There's a, apparently for MySQL, there's a MyCLI that adds context-aware completion.
I don't spend enough time in a MySQL to worry about that.
But then a couple others, if you're a Postgres person, there's somebody, something called
PGCLI that adds fuzzy search.
And then you talked about bash.
Like we spend our time on the bash command line and some of the, one replacement is called
phish that supposedly has better search history.
Oh, nice.
Yeah, that's cool.
I've heard phish is good.
I use omizeh.
And also conch is a Python-based one, which is cool as well for the shell.
Yeah.
So that was the first part.
And the second part of the series talks about how to do this sort of stuff with Python.
So he talks about actually taking four different libraries.
There's one called the prompt toolkit that you can use that to add command line, command
history, a REPL-like interface to your application.
And you can add things like command history and auto-suggestion and auto-completion, which
sounds cool, actually.
Yeah, that actually does sound pretty cool.
And then click, which I'm familiar with using click for like options and flags, but apparently
it also has a pager and the ability to launch an editor outside of it, which would be cool.
That sounds cool.
Yeah, yeah.
Very cool.
And then a couple more pigments for syntax highlighting and fuzzy finder, which is a way to make fuzzy
suggestions on whatever somebody types in.
That's cool.
And the nice thing is that it talks, there's an example on how to include, to hook up fuzzy
finder and prompt toolkit to make the completion look nice.
It's a well-written series.
And when I add interactive stuff to an application, maybe I'll check this out.
Yeah, it definitely looks cool.
You know, CLIs are great for automating things, right?
So I found a Reddit conversation.
It's not linking to an article, but it's a conversation that I thought was just outrageous for some of
the things and interesting and inspiring for others.
And it's called, how have you automated your life with Python?
So this person like throws this out as a general discussion on Reddit.
And, you know, some people come and say, you know, it is really, there's something magical
about writing code that interacts with the physical world.
And so some of them are totally straightforward.
So there's like somebody that said, hey, I take the train to work or something.
So I run a script every five minutes between five and five 30, which scrapes the train websites
and sends me a notification of my train.
It's on a delay or on time or canceled or something like that.
That's pretty cool, right?
Yeah.
Like to your Slack channel, like you better get going.
Your train's showing up early or it's late or whatever.
Yeah.
And then, so that was pretty standard, right?
Like there's another one that's a little more playful.
Like a person wrote a script to check if a nearby ice cream shop is stocking their favorite
flavor by screen scraping their menu.
Oh, nice.
Is my, is my ice cream in stock?
Yes.
All right.
I'm going to get some.
That person is passionate about their ice cream.
Yeah.
Well, have you been to Salt and Straw?
Yes.
I'd like something like that for Salt and Straw.
That'd be great.
Yeah.
For sure.
Like I wouldn't want the ice cream flavor.
I would want the line length.
Oh yeah, definitely.
Like, so those of you who are coming here for PyCon, Salt and Straw is like this, you know,
you probably heard of Voodoo Donuts, which is like a iconic donut place in Python.
People, in Portland, you'll see people with like these pink boxes all over the place.
Salt and Straw is like the ice cream equivalent.
Even in the rain, there'll be like a 30 person line outside.
It's crazy.
Yeah.
And Blue Star is better than Voodoo, but.
Whoa.
You're going to start some fights here.
Let's just move on.
So let me tell you, like, so these are all pretty standard.
Like there was somebody that said, I have a script that generates weekly status emails
off my get commit messages and creates time sheets in Harvest based on that.
Harvest is time tracking.
Like I spent three hours on this.
Wow.
That's pretty cool.
The one that like made me laugh the most.
And I don't think this is meant to be all creepy, but it could come across that way.
It's like, I recently wrote a quick Python script that tells me when my girlfriend comes
home.
Like, wait, what?
And it says it sniffs the DHCP traffic on the Wi-Fi network and looks for her Wi-Fi ID.
Interesting.
So her phone gets home, it auto joins to Wi-Fi and it sends them a note.
Like, hey, girlfriend's home.
Clean up the sink before you get yelled at.
I don't know.
Something like that.
A few weeks ago, we did one on like notifying you when your friends order pizza.
Yes, exactly.
This is kind of like that.
It's like, that's pretty interesting, but it also kind of weird.
But anyway, there's a bunch more.
I only grabbed some of them.
That's pretty interesting.
If you've automated something amazing, you know, go and stick it up there, throw it into
the chat, the discuss on this episode page.
Yeah.
Speaking of automating your life a little bit, I ran across this article and it's by the
Pi Bytes people and it's called Building a Simple Birthday App with Flask SQLAlchemy.
And the kind of the idea, which I loved behind it is they were tired of relying on Facebook
to know when their friends, when all the birthdays are coming up.
And I totally agree with that.
And also it's just kind of a fun example for how to, for building a Flask application,
which actually might be useful for people.
And I used to have a phone app that did this and I don't know what happened to that.
So I think I might actually check this out to build.
I've never played with SQLAlchemy, so maybe I'll try this out.
Yeah.
Oh, that sounds really fun.
Nice.
So yeah, yeah, that definitely is another way to automate your life.
And what we have coming up is also a, maybe an automated spelling, you might say.
But before we do, let me tell you guys about Rollbar.
As you all know, I use Rollbar for all of our sites.
Rollbar is constantly watching.
And if something crashes on the site, I get an immediate notification, maybe in Slack,
maybe my phone, all sorts of stuff.
So if you run web applications, you, or even apps that you distribute, you owe it to yourself
to work with Rollbar, right?
Go to rollbar.com slash Python bytes, and you can sign up.
It's super easy to add like to Pyramid, Flask, Django.
They have quick search for all of them.
It's like really, really new work.
And those guys are going to be at PyCon, just like Brian and me.
And they are inviting you to stop by their booth, get some swag, check them out, get a demo,
things like that.
Awesome.
Yeah.
I'll check out their booth at PyCon.
How about you?
Oh, definitely will.
I'll try to give them some of my stickers.
Yeah.
I'm definitely going to bring a sticker over there as well.
We're coming, Mike.
We're coming.
All right.
So the thing that I have next is this blog post that got sent to us.
And it's really interesting.
So at first I thought, okay, this is like kind of a somewhat interesting project that might
be worth talking about, but it's probably just something really basic, someone learning
a program.
But in fact, I think it has a lot of interesting lessons contained.
So the idea is that the article is spelling with elemental symbols.
So we know that the periodic table has a bunch of one to two character words or letters representing
elements, right?
So the idea is, can you take a regular word and spell it atomically?
So, you know, N, A, like capital N, lowercase a, capital H, right?
Something like that, right?
So can you take the stuff that's on the periodic table and make words out of it, right?
So that's basically what this does.
And it sounds kind of like, kind of interesting, but there's a couple of things that are worth
looking at.
One is you can look at a word and you can break it up into this piece and say, okay, well,
this is consists of like, maybe it's a four letter word, consists of one, one, one, one
possible letter arrangements, or it could be two, one, one, or one, one, one, two, right?
Like there's, there's different ways in which you might pull those letters into the chemical
elements, right?
But if you look at the length of a word, say there's 10 characters in a word, how many
possible combinations of that are there?
Would you guess?
Yeah, I'm really bad at math.
Don't remember.
Well, not so much the number, but the formula for it, like the concept for it.
It turns out that the number of these arrangements based on the number of characters is the Fibonacci
sequence.
Oh, wow.
Okay.
Isn't that crazy?
So if you've like a five letter word, there's whatever the sixth value of the Fibonacci numbers
is.
That's how many possible options are.
10 letters of the 11th Fibonacci and so on.
It's like N plus one, basically.
Isn't that crazy?
Yeah.
Just, I want to randomly grab stuff off the periodically table Fibonacci.
Okay.
So that's pretty interesting, but it turns out like the guy was doing a bunch of work to sort
of break these apart.
The really computational part is given a word, how many of these Fibonacci numbered partitionings
are there, right?
That's where most of the work was.
So he said, okay, well, I tried to optimize it in a couple of ways and he does a lot of
interesting performance profiling.
So you can learn how to profile your code there, which is really cool.
And it turns out, you know, it was really slow doing that.
So he's like, all right, well, what else can I do?
Maybe I can use memoization.
Have you heard of memoization?
You know what this is?
Don't quiz me on it, but yes.
Okay.
Yes.
All right.
So if you have a function that is stateless, right?
It just works on its input parameters and then it gives you back a number or a value based
solely on the input.
You can use this idea called memoization to say, basically cache the input arguments and
then the potentially expensive output.
So if you get, you know, a word of length seven, well, you know, you can, you know how, what
like the seventh Fibonacci arrangement of these things is and you don't ever have to compute
it again.
So he's like, well, let's try this to make it faster.
And it turns out that it did make it faster, but like 30%.
So it went for like whatever his data set it was.
It went from like 22 minutes to 60 minutes or, or something to this effect.
So that was better.
And then he said, all right, let's rethink this algorithm, switch to a directed acyclic
graph using recursion.
And the complexity went from O2 to the N to O of N and the time to compute all these,
um, these sort of weird spellings, if you will, went from 16 minutes to 10 seconds.
Wow.
So, which is really cool.
So he takes this pretty easy to understand problem and, and works through it and does profiling,
complexity analysis, memoization, recursion graphs.
And there's just a lot of stuff to learn.
And if you're kind of getting started with some of these ideas, this is a very approachable
way to, to get at some of it.
That's what I like about this love about this article is it's not, it's not really that you
really have this need for this application.
It's this kind of a problem.
And how do you approach it from a computer science standpoint to, and an engineering standpoint
of faster is better and getting down to it.
It's pretty cool.
Yeah, it is really cool.
And it's, there's something super rewarding about writing code that goes, it takes 22 minutes
to run and getting that down to 10 seconds.
Yeah.
You're just like, yes, I beat you.
I beat you problem.
Now you just got to get it to run on GPUs and get it sub, sub second.
Sub second.
Yeah.
So speaking of, helping people learn and get started, you've got something cool for us.
Yeah.
Well, actually I'm not sure if it's cool or not.
Um, I ran across, another Reddit comment thread and this one is a discussion about
a, an IDE called, I think it's Tony Thonny, T H O N N Y.
Any guesses on how to pronounce that?
I'm going, I'm going with Thonny.
But I'm not sure.
So that there's a discussion about whether or not about the merit of this particular IDE.
And I haven't tried it.
I have to, to be real honest, but I have mixed feelings about encouraging beginner IDEs.
I guess mostly I don't know if it's a good idea or not.
I think, parting, learning how to use a decent editor is kind of part of how to learning
how to be a programmer.
So actually I was just curious about what you thought about beginner editors.
I did look at this and I also had mixed emotions about it.
It was like interesting, but I'm not entirely sure that I would recommend it.
And I, I don't really know why, but I definitely think it's, it's quite interesting to see what
it does.
So I'll just, there's, there's like a little video and stuff.
You guys can click the link and check it out.
But imagine, an IDE where you have like a Python file and you type in it and then to
the right of it, like a little tab that says, these are all the variables that are in your
code.
Right.
So that's kind of cool that you can actually see the variables that are at work while you're
writing your code.
Now, obviously we don't need that these days, but you know, when you're new, like those things
get lost.
Right.
Yeah.
And so that's really nice.
It has like a single button debugging experience.
Okay.
Which is pretty cool.
And then it has like, while you're debugging it, it has a shell and you can like type stuff
in the shell, like, like a REPL basically.
And it'll like, let you explore the state of the program, I believe, if I'm understanding
it correctly.
So those are all pretty interesting things.
Okay.
Maybe I'm changing my mind because like ID, full blown ID, like Visual Studio or something,
or even PyCharm might be a little overwhelming for somebody just starting out, but learning
the concepts that an ID might be able to give you, maybe that's a good thing.
Yeah.
Maybe it is.
I mean, one thing that's cool about it is it comes with Python 3.6 built in and it's a
Windows app.
Okay.
Right.
So you just install it and you open it up and then boom, you have Python 3.6.
You don't have to think about, oh my God, VCVars.bat.
Where's the path?
Why is this not working?
You know what I mean?
Like all that, that grief just kind of goes away and that's pretty cool.
Yeah.
It probably doesn't have Vim key bindings though, but.
No, probably just Emacs.
Probably Emacs?
You think so?
I don't know.
Probably none.
It's probably just a GUI thing.
So.
Yeah, probably.
But no, it looks, you know, I'm not going to do anything with it, but it definitely looks
interesting if you're trying to teach people, especially maybe kids.
I'm not entirely sure, but I think it might be good for that group.
And the idol is kind of in that same category.
But I guess I brought this up here because I'd like to hear some comments from our listeners
as to whether they encourage people to use beginner IDEs when they're teaching programming or not.
Yeah, for sure.
Leave a note on the end of the show notes, the show page, pythonbytes.fm/26 for this one.
All right.
Last thing.
I have some salvation for the PDF people out there.
So a lot, especially if you're in data science or doing web scraping and trying to get data,
often it's bundled up in these reports, which are in PDFs.
And the support for actually going into these PDFs and getting them out in Python has not been good.
It's really, you know, I've had a lot of people say, I've tried this, I've tried this, I've tried this.
None of them work.
Do you have any ideas, Michael?
And I say, nope, no ideas.
So there's recommendation on Twitter that I thought was really good from Dan Schorstein.
And he said, hey, you should check out this thing called PDF Plumber.
So you can go in and you can extract graphs.
You can debug your processing of the PDF file visually.
Oh, wow.
So if you're trying to extract a table, you can go and say, you'll highlight the thing I'm looking for like this.
And it'll literally show you a PNG with like rectangles around the pieces you're getting.
Which is pretty cool.
So you can extract a bunch of tables.
You can work with the shapes.
You can group stuff together.
Somebody did like a master's thesis on this.
And a lot of those ideas are brought into it.
So if you're out there doing data science and or something where the data is wrapped up in PDFs and you've been having a hard time getting at it, check out PDF Plumber.
Great.
Awesome.
Yeah.
Very good.
So that's our news for this week.
Anything you've got, what, like a day to finish the book?
How's that?
No, I had last Wednesday.
Do you have two days?
No, I turned it in already.
You did?
Yeah.
Oh, man.
Congratulations.
How does that feel?
It's not done yet.
So the first five chapters will be, five chapters?
Yeah.
The first five chapters will be released unofficially in stealth mode on the 17th.
Awesome.
And that's tomorrow.
Just in time for PyCon.
Or either that or today or yesterday, depending on when people get this.
It could have been three weeks ago if you listened to this very lately.
Yeah.
Awesome.
But definitely by the time I'm hanging out at PyCon, it'll be available.
That's cool.
Official release is supposed to be next.
So this is the Python testing with pytest.
Even as is, the first five chapters are like 10 times better than anything I've ever read before.
Oh, that's awesome.
Yeah.
Congrats.
How about you?
What's going on?
Well, I am really looking forward to being at PyCon.
I'm going to be there Thursday night.
We'll have our booth there.
And Thursday, Friday, Saturday, Sunday, we'll have our booth set up.
People come hang out with us, come talk to us.
And we'll be doing some open sessions and things like that.
So it'll be a lot of fun.
Yeah.
So I'm definitely looking forward to that, being there with you and all the other podcasters.
And I actually just finished recording my RESTful HTTP services in Pyramid course.
And that's all totally done.
I'm just waiting on the final edits to publish that to the world.
And I'm now working on my MongoDB for Python developers course.
So I'm frantically writing as fast as I can before PyCon overwhelms me.
Oh, nice.
Okay.
Yeah.
Those are both going to be fun.
Great.
Cool.
All right.
Well, that's all I got.
That's about it for me.
Yeah.
Same here, man.
Well, welcome back to the US.
And I will see you and everyone else at PyCon.
Yeah.
See you in a couple of days.
All right.
Bye.
Thank you for listening to Python Bytes.
Follow the show on Twitter via at Python Bytes.
That's Python Bytes as in B-Y-T-E-S.
And get the full show notes at Python Bytes.fm.
If you have a news item you want featured, just visit Python Bytes.fm and send it our way.
We're always on the lookout for sharing something cool.
On behalf of myself and Brian Okken, this is Michael Kennedy.
Thank you for listening and sharing this podcast with your friends and colleagues.