Parsing & question about usages off classes!

Alex Martelli aleax at aleax.it
Sun Nov 3 17:14:12 EST 2002


Frans wrote:
   ...
> I want to create several new list. The name off the new lists will come
> from another list. That way I can create several lists, depending on the
> data received from logfiles. Is that possible ?

(just about) everything is possible, but not everything is helpful.
That's the gist of the "1 Corinthians, 6:12" I mentioned earlier.


> Or isnt that a good idea either ? :)

Exactly.  It's NOT a good idea to create variables with names that
you do not know at the time you're writing your code.  It's _possible_
(because Python doesn't go out of its way to forbid the programmer to
follow suboptimal strategies: rather, Python focuses on simplicity and
regularity), but you're better off doing something else.

For example, consider *dictionaries*.  Why couldn't you use entries
in dictionaries, rather than creating different variables?  After all,
variables are often little more than entries in dictionaries.  By
creating entries in dictionaries, you keep things in your program MUCH
more under your control, avoiding the all-too-likely accidents that
are typically triggered by creating variables with unknown names --
such as accidentally rebinding names you still need for other reasons,
or hitting on a keyword (reserved word) such as e.g. 'print' or 'try'
and having mysterious syntax errors because THAT name isn't allowed.


Alex




More information about the Python-list mailing list