[Tutor] Learning Project Proposal (was: Help needed?)

Bryan Hann bryan.hann@pobox.com
Fri, 17 Sep 1999 03:05:56 +0800


Wayne,

I post this to the list because it might be a worthwhile
learning project for others here.

I have a little project that might be nifty.  I assume you 
are familiar with regular expressions.  Python's re module 
leaves some things to be desired.  Suppose I want to build 
a RE to match identifiers built out of letters, numbers and/or 
underscores, but not starting with a number.  This pattern 
should work:

    identifier="(_|a-z|A-Z)(_|a-z|A-Z|0-9)*'

But things can soon get messy. It would be nice to be able to
write something like

    letter="_|a-z|A-Z"
    digit="0-9"
    identifier="letter+(letter|digit)*"

But identifier is a pattern that, roughly speaking, does not 
match strings beginning with a letter, but instead matches 
strings that begin with the string "letter+" -- clearly not 
our intent! I propose a reBuilder class that will work like 
this:

    >>>foo=reBuilder()
    >>>foo.letter="_|a-z|A-Z"
    >>>foo.digit="0-9"
    >>>foo.id="letter+(letter|digit)*"
    >>>foo.letter
    "_|a-z|A-Z"
    >>>foo.digit
    "0-9"
    >>>foo.id
    "_|a-z|A-Z((_|a-z|A-Z)|(0-9))*"

The class will work roughly by redefining __setattr__ and 
__getattr__ to make objects

1. accept re components in the form foo.x=y,
2. rewrite y appropriately, then
3. store (x,y) in the dictionary
4. have "foo.x" return the stored string 

Rewriting will involve at least scanning y for substrings 
referring to previous components, and removing '+' and adding 
parentheses as necessary.  More is needed to handle the full
re syntax in the re module, but it will not be hard, and if 
you are very new to Python, you might find it nicely reinforces
some of the nicer semantics of the language. I will begin 
writing soon.  If this interests you, why don't we develop in 
parallel, and compare our results?  We can swap ideas along the 
way.  It should be a small project.  If we want to extend it, 
we can unify our strategy and divide the work.  

Cheers!
--Bryan

Wayne wrote:
> 
> ...I know I'm going to regret this, but I've recently started learning Python
> {I know a little [Perl, Java, C, C++, Scheme, Clips], enough to cause problems
> on the system without understanding what went wrong}.  However, I don't have
> any ideas on good projects to start working on to help solidify the learning.
> 
> My question....does anyone need help with a project they are working on?  Most
> of the time I have will be on the weekends.  I was thinking about starting to
> port various Perl modules to Python as a way to get more familiar with
> things.
-- 
==================================================================
 Bryan Hann -- bryan.hann@pobox.com -- www.pobox.com/~bryan.hann
 The RITE Group: Researching Information Technology in Education.
==================================================================