* Ben North <[EMAIL PROTECTED]> [2007-02-11 23:45:05 +0000]: > Dynamic attribute access is currently possible using the "getattr" > and "setattr" builtins. The present PEP suggests a new syntax to > make such access easier, allowing the coder for example to write > > x.('foo_%d' % n) += 1 > > z = y.('foo_%d' % n).('bar_%s' % s) > > instead of > > attr_name = 'foo_%d' % n > setattr(x, attr_name, getattr(x, attr_name) + 1) > > z = getattr(getattr(y, 'foo_%d' % n), 'bar_%s' % s)
Clipper (and other members of the "xBase" family) have something vaguely similar, and from working with that syntax, my feeling is that this is too "subtle" given the mixing of levels going on here (a "literal" name vs. an expression evaluating to a name). That is, it's too easy to not properly notice the presence / absence of the () and become confused between foo.bar and foo.(bar) or similar. (For the curious, the Clipper syntax is generally used in "commands" which are a kind of statement that is macro-evaluated; so, for example, something like this: USE clients will be transformed into something like the following expression: dbUseArea("clients") during the preprocessor pass, care of a "builtin" definition of USE; this function has the effect of opening a database file on disk for use. Now, in order to use the command syntax with a database name stored in a variable, one does something like the following: USE (dbName) which is transformed into something like: dbUseArea(dbname) with similar effects as before.) -- mithrandi, i Ainil en-Balandor, a faer Ambar
signature.asc
Description: Digital signature
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com