Modifying the {} and [] tokens
Jeremy Bowers
jerf at jerf.org
Sun Aug 24 15:53:20 EDT 2003
On Sun, 24 Aug 2003 01:50:01 +0000, Geoff Howland wrote:
> Since
> it's not possible, I'll think up some other less hacky slightly more
> verbose way to handle the issues.
Well, if this is internal code only, you can always simply do
from MyDictClassThiny import D
a = D('a', 'b', 'c', 'd')
or whatever syntax you can cook up in Python that you might desire.
The other route you might consider, again for internal code only, is just
biting the bullet and writing a quick code pre-processor that converts {}
into a call to your class instead. (Getting it to understand {a: 2}, etc,
would not be hard.)
The odds of the general Python language supporting what you are looking
for are slim to none, but you aren't necessarily stuck with *pure* Python
if you've got group resources. Personally I'd recommend the pre-processor,
because it could be run separately later to produce "pure" Python which
could be useful, rather then hacking the C, which will never be generally
useful. The pre-processor is pretty easy to write here.
You might also consider taking a little time a few weeks into the project
and experimenting with just using the pre-processor output directly. You
might find the perceived advantages failed to materialize. (Or not.)
More information about the Python-list
mailing list