Python is fun (useless social thread) ;-)

Bruno Desthuilliers onurb at xiludom.gro
Wed Jun 21 05:04:24 EDT 2006


BartlebyScrivener wrote:
>>>>You know what are dicts, right ? That is, containers with
>>>>keyword-access to values ? Then you probably have dicts
>>>>with a known, defined structure, and functions working on
>>>>it. What classes (and hence 00) gives you is a way to
>>>>associate these functions with the dicts themselves. That
>>>>is the big intuition about objects, the rest is just
>>>>details.
> 
> 
> You bet. 

No big deal. Using dicts to organize data is quite obvious, and then you
need to operate on these data, so you write functions using these dicts...

> I have lots of these.
> Especially a large dictionary that is
> kind of an application and site launcher. I type "l clp" at the command
> line, and l.py runs a function def launch(obj), which grabs the key
> "clp" whose value is this site address, and I'm browsing clp. Kind of
> like favorites with no mouse. Or another dictionary with applications.
> Same way. They work fine. I guess they aren't complex enough to require
> classes yet?

Nothing really *requires* classes if you go that way. Now going from
dicts+functions to classes+methods is quite a no-brainer, and can really
ease maintenance. Once you'll be there, you'll probably find yourself
shifting to a more OO style (small decoupled methods, polymorphic
dispatch etc) swithout even noticing. You don't have to learn all the
voodoo stuff about OO to start using OO in Python - but if you already
made the move from strictly procedural (dicts/lists/tuples + functions)
to ADTs (simplest use of classes), you'll be happy to have the whole
power of Python's object model when the need arise.

> I appreciate the tips. I'll do a couple tutorials and read my books and
> then come back with any OO questions.

You're welcome. FWIW, a good exercice would be to take one of your own
programs and try to gradually transform dicts+related funcs to classes.

My 2 cents
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list