I taught David Beazley’s 3-day Intro to Python class in Austin last week, and I really enjoyed it. I’ve always liked speaking in front of people (well, after the very first time, which was terrifying), and three days with a group of 15 made for a good intimate dynamic.
Interestingly, I learned a few tidbits about Python along the way:
- The builtin enumerate() function has a two-argument form so that you can specify the first numbering value: enumerate(seq, start), handy for numbering lines in files, which should of course start with 1, not 0.
- The -i switch to the Python interpreter will run your program, then leave you in the command prompt when it ends. This can be good for interactively testing the functions defined in the file, or for debugging if an exception happens.
- If you use “python -i” and need to debug, pdb.pm() is the thing to use. It places you at the point where the last traceback was raised. It seems like magic, since the exception has already risen to the top level of the program, but pdb.pm() puts you “back in time” before the exception started its climb up through the stack.
- 4 + True == 5. Useless, but there it is.
I liked explaining Python’s elegant power, and it’s fun to show experienced C programmers a different way of looking at programming. Trying to fit all the material into three days is a challenge, and there are interesting side-topics that I know we can’t get into, which is a shame, but there’s only so much you can do in a given amount of time.
Austin was a really fun city to explore on my own, too. If I had been more confident that I’d have energy left at the end of the day, I’d have tried to arrange some social events with other Python peeps. But the “Keep Austin Weird” vibe made it easy to wander around and find food trucks to eat at. My first night, driving down East 6th street, I saw a cluster of closed food trucks, with just one open, lit like a beacon at the back:
How could I not eat at a tiny truck named Pig Vicious manned by a giant tattooed bearded cook?
Comments
You could just as well do that using a filter: > I wonder if it's fixed in Python 3.
As far as I know, it is not considered broken by the core team.
True/False being a subclass of int is long-story-short a product of history. Before python 2.3 TF were undefined; they were added to builtins because it was very popular to define True = 1 and False = 0. Making them keywords would have disallowed assigning to those names and broken a lot of code.
In 3.x they _are_ keywords so you can't assign to them. They still are a subclass of integer though. Why? because it doesn't really hurt anything and makes the Objects/boolobject.c implementation just 184 lines long - versus 4889 lines for Objects/longobject.c
You can have something like: to choose from a list without in the middle of string interpolation.
Filter is slow and deprecated since comprehensions became available. So the solution above using it is pretty bad.
filter(condition, list) is the same as [i for i in list if condition(i)].
But, instead of creating a new list, how_many = sum(condition(x) for x in my_set) uses an interator and saves memory.
P.S. Ned - how the heck are you? how goes the solo gig?
That's 4 + True, not 4 + TRUE.
(Posted at midnight on a Saturday night. Go figure.)
Add a comment: