map document in walkable way...

Emile van Sebille emile at fenx.com
Thu May 30 15:12:00 EDT 2002


"Shagshag13" <shagshag13 at yahoo.fr> wrote in message
news:ad5sj4$urrdt$1 at ID-146704.news.dfncis.de...
>
> I have document which contain lines :
>
> type 2
> type 1
> type 1
> type 2
> etc.
>
> I would like to create some kind of class that i could use to map my
> document and use it in a walkable way :
>
> d = document(file)
> for l in d:
>     if l.is_type1():
>         do_something
>     elif l.is_type2():
>         do_something_else
>

def do_something(d): pass
def do_something_else(d): pass
do_on_type = {'type 1':def do_something, 'type 2':def do_something_else}

for l in d: do_on_type[l](d)

flavor to reqs and HTH,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list