Thursday, February 26, 2009

TuPLE (Tucson, AZ) - First official meeting recap

TuPLE (Tucson Python Language Enthusiasts) is off to a good start. Our first official meeting went well, with 6 attending.

Chris Merle started us off with an overview of Plone and two products that help to
inspect and interrogate the python objects in use:
DocFinderTab
DocFinderTab adds a tab to the ZMI that parses the docstrings of the class of the object you are using and presents them to you in the tab.
Clouseau
Clouseau embeds a live ajax based python interpreter into your plone site for debugging purposes. It looks to have some nice autocompletion features and lets you poke around the internals of a live instance.

Chris then demoed his news portlet modification that shows an excerpted portion of the news items (vs just the title and link), and explained how DocFinderTab and Clouseau both helped him determine which object attributes were going to be useful for displaying the content.

We had some good conversation about general interests, IDEs, reference books, and what kinds of presentations everyone is interested in. Django, advanced python, and C extensions are heading up the list for the future.

Misc. Notes:

  • Civilization 4 allows mod authors to use Python to modify aspects of
    the game. Hopefully we'll hear more about it in the future.
  • PyScripter - Free Windows Editor/IDE
  • Core Python (http://corepython.com/) was recommended as a good
    reference, others thought the online docs were adequate.
  • A couple of members are repeat pycon attendees. This year we'll have 2
    or 3 attending. April's meeting will be good for a pycon recap.
  • A python obfuscation tool was discussed
Thanks to Chris for presenting and everyone for attending!

Friday, February 20, 2009

DFW Pythoneers, 2nd Sat: Topics We Covered

The 2nd Saturday of February meeting of the DFW Pythoneers went well, with 5 people showing up even though it was Valentine's Day. We covered a grab bag of topics I'd researched ahead of time. It was part of a new plan of mine to structure our meetings a bit, by each month covering (1) a module in the standard library, (2) a programming concept, (3) a source code walkthrough and (4) a few "how would you do this?" type of questions. Feedback on this approach is welcome.


For the module in the standard library, we briefly covered the new print() function in Python 2.6:
from __future__ import print_function  # Python 2.6                                        
print(objects..., sep='', end='\n', file=sys.stdout)
and then the new .format() method on strings, as an alternative to the C style sprintf("%s %d", a, b) approach. The format() approach is more powerful than the % operator but takes some getting used to.

Feedback from some attendees is that it is too complicated, so we also covered the much simpler but less powerful Template module in the standard library.
  >>> from string import Template
>>> s = Template("$who likes $what")
>>> s.substitute(who='tim', what='cake')
tim likes cake
>>> s.substitute(who='tim') # error
...
>>> s.safe_substitute(who='tim')
tim likes $what

For the programming concept, we studied sequence slicing and subscripting.

While most of us have a good grasp on simple subscripting and from:to slicing, there are some deeper aspects here, a few of which can be seen in:
  a[4:5:5]    # extended slicing, with a stride
a[3, 4, 5] # a slice list
a[2:4, 5:7] # list of slices
a['a':'c'] # applying slicing to non-integers and non-ordinal content
We also looked at the deceptively simple shallow copy operation:
a[:]
and how it differs between mutable (list) and immutable (tuple) types.

And then we looked at the little-known builtin type 'Ellipsis' and how it can be used in your own programs.
  a[...]
a[..., 0] -> mapobj[:,:,:,0] # PyNumeric interpretation
In order to experiment with the various subscript/slicing syntaxes, we defined our own __getitem__, __setitem__ and __delitem__ methods to print out what was received:
  >>> class alpha:
... def __getitem__(self, key):
... print "Key is %s" % repr(key)
... return None
...
>>> a = alpha()
>>> a[3, 4. 5]
...

Next we took a little trip over to look at the issues and concerns involved in the simple idea of sorting items in a collection:

We studied the difference between the .sort() method and the sorted() builtin function, and the three arguments (cmpfn, key, reverse) you can pass to either one.

This also brought us into the operator module which has several useful functions for extracting values on which to sort from items, such as:
  key=operator.itemgetter(1)
key=operator.attrgetter('eggs')
and we talked about (but didn't dig into) the well-known design pattern of "decorate-sort-undecorate".
For the questions of "how would you do this?" we discussed:

  • How can you test for whether a variable is defined?

  • How do you tell if a method is bound or unbound?

  • How do you 'unbind' a method?

  • How do you set an attribute whose name is not a legal Python name?

  • How can you conditionally define methods in a class?

  • How do you change the data underneath a mutable sequence without breaking any existing bindings to the sequence itself? Hint: Look in site.py.


For the source code walkthrough we examined the implementation of the string Template class in lib/python/string.py. The interesting part was its use of a metaclass to post-process the extraction strings defined in the class into compiled regular expression objects.
And by special request by a member, we looked into how Python at startup arranges its module import path (sys.path) to find zip/eggs and parses 'path configuration files' (.pth) that alter that path. We also covered the privileged status of 'site' directories over other directories on the path and did a very quick walkthrough of the source in lib/python/site.py as well as the lib/python/site-packages/site.py installed by setuptools.
That filled our 3-hour session and we wrapped up with chatter about the rapidly approaching PyCon and the early registration deadline.

Sunday, February 8, 2009

pyCologne Python User Group, Cologne, Germany, February, 11th, Announcement

The next meeting of pyCologne will take place

Wednesday, February, 11th
starting about 6.30 pm - 6.45 pm
at Room 0.14, Benutzerrechenzentrum (RRZK-B)
University of Cologne, Berrenrather Str. 136, 50937 Köln, Germany

Agenda:
  • Programming mobile phones using Python (Andreas Schreiber)
  • MoinMoin (Moin 1.8.x Wiki with stand-alone-server / plugins)
    (Reimar Bauer)
At about 8.30 pm we will as usual enjoy the rest of the evening in a nearby restaurant.

Further information including directions how to get to the location can be found at:
http://www.pycologne.de (Sorry, this page is in German only)