Thursday, July 31, 2008

DFW Pythoneers, 4th Sat July, Topics Covered

For the 4th Saturday meeting of July, we had a good group show up for the beginners session at 1pm. The target audience were existing programmers new to Python. We had 10 people besides myself there and then at the regular 2pm start time, some people left and some came in, raising it to 12 people. I presented on the underlying concepts of Python that make it easy to learn yet powerful.

We covered introspection at the Python prompt, using dir(), type(), id() and help() to examine your environment as well as the useful "python -v" and "python -i" arguments. Then we got into names and values and how they are organized into namespaces everywhere you turn in Python. We got into the differences between 'is' and '==', mutability, shared vs non-shared structures and whether names are by-ref or by-value. I went over the simple values then the compound values like mappings, sequences and sets.

Around 2pm when the main meeting began we went over how a Python source file is structured, how it gets converted into multiple codeblocks, which are executed immediately and which are executed later. This was a tricky concept for some with lots of discussion. We covered how the Python module system is derived from that for Modula-3, the various kinds of import statements, the true meaning of the global statement (i.e. not really global overall), how modules are aggregated into a navigable top-level set of in-memory namespaces and some of the metadata you can find in them, like __name__ and __file__.

We took a look at the most common modules all programmers should know, such as __builtins__, sys, os, os.path, string and re (derived from Perl), and a bit on the types module. We reviewed the various control structures that Python gives us and also the ones it lacks, such as switch/case and do/while. We looked at the exception model of Python, how it differs from other languages in its continuability and restartability and the correct usage of exceptions in Python for error conditions, not normal control flows.

We touched lightly on the underlying behavior protocols of Python, for object, number, sequence, mapping, iterator and buffer, how Python uses protocols instead of class derivation for grouping behavior. We then got into Python's idea of OOP, the topmost object class, initializers/destructors and the binding of self and what it means when you have an unbound method. We sidestepped metaclasses and the type hierarchy for now but got in a mention of ducks (type peeking), turtles (all the way down) and monkeys (patching).

And because it is such a key concept, we went over 'callables', how different things can be called transparently and the powerful argument passing mechanism Python uses re positional, keyword and default. We touched a bit on what it means to be iterable and moved on to the more concrete ideas of being subscriptable, from/upto, negative ordinals and subscript ranges or slicing. The third slice argument for skipping, forward and backward, was a popular topic.

It was almost 5pm by then and we were running out of time, so we briefly covered predicates; if a == b, if a is b, if a/not a, and the has_key (in) and hasattr tests. We wrapped up with a couple of short code walkthroughs just to see the concepts in use.

----
This kind of presentation was an experiment to see if there is a demand in our group for a return to the basics of the Python code instead of covering the web framework flavor of the week. Based on this first response, it seemed popular so we'll do it some more at future meetings. I'm going to try to break it apart into relatively standalone topic chapters and, when I do, make those materials available online.

I'll be at WorldCon during our 2nd Sat meeting of August but we'll do this again for the 4th Sat meeting.

2 comments:

David Christian said...

Hey Jeff,
I am getting a large number of newbies at the NYC Python meetings and have been thinking of doing something like this myself, but wasn't quite sure where to start. This seems like a great list of core concepts and an order that makes sense.

Thanks for posting this!

Anonymous said...

I would like too take some time out thank the active members for doing what you do and making the community what it is im a long time reader and first time poster so i just wanted to say thanks.