Re: String To Dict Problem

2006-04-22 Thread Clodoaldo Pinto
Michael Spencer wrote: Alternatively, you could edit visitName to allow 'True' and any other identifiers you specify e.g. (untested): allowed = {True: True, False: False} def visitName(self,node, **kw): try: return self.allowed[node.name] except

Re: String To Dict Problem

2006-04-21 Thread Clodoaldo Pinto
Michael Spencer wrote: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 Very nice work. It will be very useful. Thanks. Only a small problem when I try to evaluate this: safe_eval('True') I get: Traceback (most recent call last): File safe_eval.py, line 63, in ?

Re: String To Dict Problem

2006-04-21 Thread Michael Spencer
Clodoaldo Pinto wrote: Michael Spencer wrote: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 Very nice work. It will be very useful. Thanks. Only a small problem when I try to evaluate this: safe_eval('True') I get: Traceback (most recent call last): File

Re: String To Dict Problem

2006-04-21 Thread Felipe Almeida Lessa
Em Sex, 2006-04-21 às 18:40 -0700, Clodoaldo Pinto escreveu: Only a small problem when I try to evaluate this: safe_eval('True') Change def visitName(self,node, **kw): raise Unsafe_Source_Error(Strings must be quoted, node.name, node) To

Re: String To Dict Problem

2006-03-28 Thread [EMAIL PROTECTED]
def default(self, node, **kw): for child in node.getChildNodes(): return self.visit(child, **kw) visitExpression = default I'm not sure I grok this part. It leads to unexpected results: safe_dict(gid = 'FPS', type = 'Label', pos = [0, 20], text = 'FPS', text2 =

String To Dict Problem

2006-03-26 Thread Kamilche
Hi everyone. I'm trying to convert a string that looks like this: gid = 'FPS', type = 'Label', pos = [0, 20], text = 'FPS', text2 = 'more text without quotes', fmtline = @VALUE @SIGNAL, signals = [('FPS', None), ('FPS2', 'something')] to a dict that looks like this: {'signals': [('FPS', None),

Re: String To Dict Problem

2006-03-26 Thread Michael Spencer
Kamilche wrote: Hi everyone. I'm trying to convert a string that looks like this: gid = 'FPS', type = 'Label', pos = [0, 20], text = 'FPS', text2 = 'more text without quotes', fmtline = @VALUE @SIGNAL, signals = [('FPS', None), ('FPS2', 'something')] to a dict that looks like this:

Re: String To Dict Problem

2006-03-26 Thread Kamilche
Thanks! It's interesting, and nearly what I want, but not quite there. When I run my sample code through it, I get a syntax error because it's not a valid expression. If I were to put a 'dict(' in front and a ')' at the end, THEN it nearly works - but it gives me an 'Unsafe_Source_Error: Line 1.

Re: String To Dict Problem

2006-03-26 Thread Michael Spencer
Kamilche wrote: Thanks! It's interesting, and nearly what I want, but not quite there. When I run my sample code through it, I get a syntax error because it's not a valid expression. If I were to put a 'dict(' in front and a ')' at the end, THEN it nearly works - but it gives me an

Re: String To Dict Problem

2006-03-26 Thread Kamilche
Ah, finally, that's exactly what I need! Thanks bunches. I was attempting to modify your first code to fit my needs, but mine was much longer, and not yet working, a sure clue that yours is a better solution. :-D -- http://mail.python.org/mailman/listinfo/python-list