Life's better without braces

Bernhard Herzog herzog at online.de
Fri Feb 25 18:19:24 CET 2000


Christian Tismer <tismer at tismer.com> writes:

> Gerrit Holl wrote:
> > 
> > Hello all,
> > 
> > I have a problem. In my Python enthuishasm, I ripped off the braces
> > from my keyboard because I thought I didn't need them.
> > Unfortunately, I have a problem now. I can't create dictionairies any
> > more! And because braces aren't the only keys on the brace key,
> > I can't create lists either. The solution for the latter is list(()),
> > but how do I create an empty dictionairy without braces?
> > 
> > I know I can do:
> > >>> import os
> > >>> d=os.environ.data
> > >>> for k in d.keys():
> > ...     del d[k]
> > ...
> > >>> d
> > {}
> > 
> > But is there a more efficient way to do it? Does the 'new' modules has
> > something I want?
> 
> >>> class braces:
> ... 	def __call__(self): return self.__dict__
> ... 	

shouldn't this return a copy of the dictionary?

> >>> dic = braces()()
> >>> dic
> {}
> >>> 

> Well, the lack of [] doesn't make this too useful.

you could always use the get method.

[...]
> > HELP!
> > 
> > If I'll rip off the ';' too, I won't be able to type blocks any more,
> > since I won't be able to type a ':' either. Hmm, is it safe to rip
> > off the '$'? I don't need a '4'!
> 
> I just successfully ripped out my ";", and it still works fine.
> Hint : use a German keyboard.
> Well, I'm missing the comma a little now.
> No problem, since I can always change tuples to lists, modify
> them and tuple them back.

How do you call functions with more than one argument now? apply() isn't
very helpful in this case. The only thing I can come up with is to use
exec or eval and encode the comma in the string with \054. Of course,
you could always use cut and paste...


-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list