Re: weird dict problem, how can this even happen?

2008-12-19 Thread Scott David Daniels
Joel Hedlund wrote: Scott David Daniels wrote: Perhaps your hash function could be something like: I'm not sure I understand what you're suggesting. /Joel Sorry, a half-thought out idea based on the fact that you wanted a consistent hash for a varying dictionary. The given dictionary subcl

Re: weird dict problem, how can this even happen?

2008-12-19 Thread Joel Hedlund
Joel Hedlund wrote: First off, please note that I consider my problem to be solved, many thanks to c.l.p and especially Duncan Booth. But of course continued discussion on this topic can be both enlightening and entertaining as long as people are interested. So here goes: heh, nothing like a

Re: weird dict problem, how can this even happen?

2008-12-17 Thread Joel Hedlund
Steven D'Aprano wrote: On Tue, 16 Dec 2008 14:32:39 +0100, Joel Hedlund wrote: Duncan Booth wrote: Alternatively give up on defining hash and __eq__ for FragmentInfo and rely on object identity instead. Object identity wouldn't work so well for caching. Objects would always be drawn as they ap

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Steven D'Aprano
On Wed, 17 Dec 2008 02:10:31 +0100, Joel Hedlund wrote: > Scott David Daniels wrote: >> Perhaps your hash function could be something like: > > I'm not sure I understand what you're suggesting. Neither am I, since you've removed the hash function which might have given readers a clue. *wink*

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Steven D'Aprano
On Tue, 16 Dec 2008 14:32:39 +0100, Joel Hedlund wrote: > Duncan Booth wrote: >> I think you probably are correct. The only thing I can think that might >> help is if you can catch all the situations where changes to the >> dependent values might change the hash and wrap them up: before >> changin

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Joel Hedlund
Scott David Daniels wrote: Perhaps your hash function could be something like: I'm not sure I understand what you're suggesting. /Joel -- http://mail.python.org/mailman/listinfo/python-list

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Scott David Daniels
Joel Hedlund wrote: Duncan Booth wrote: I think you probably are correct. The only thing I can think that might help is if you can catch all the situations where changes to the dependent values might change the hash and wrap them up: before changing the hash pop the item out of the dict, then

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Joel Hedlund
Duncan Booth wrote: I think you probably are correct. The only thing I can think that might help is if you can catch all the situations where changes to the dependent values might change the hash and wrap them up: before changing the hash pop the item out of the dict, then reinsert it after the

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Duncan Booth
Joel Hedlund wrote: > I should probably do this with lists instead because I can't really > think of a way of salvaging this. Am i right? > I think you probably are correct. The only thing I can think that might help is if you can catch all the situations where changes to the dependent value

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Arnaud Delobelle
Joel Hedlund writes: > I'm having a very hard time explaining why this snippet *sometimes* > raises KeyError: > > snippet: >> print type(self.pool) >> for frag in self.pool.keys(): >> if frag is fragment_info: >> print "the fragment_info *is* in the pool", hash(frag), >> hash(fragmen

Re: weird dict problem, how can this even happen?

2008-12-16 Thread Joel Hedlund
Duncan Booth wrote: It could happen quite easily if the hash value of the object has changed since it was put in the dictionary. what does the definition of your core.gui.FragmentInfo object look like? Dunno if it'll help much, but: class FragmentInfo(object): def __init__(self, renderer,

Re: weird dict problem, how can this even happen?

2008-12-15 Thread Duncan Booth
Joel Hedlund wrote: > I would very much like an explanation to this that does not involve > threads, because I haven't made any that I'm aware of. I can't even > understand how this could happen. How do I even debug this? > It could happen quite easily if the hash value of the object has chang

weird dict problem, how can this even happen?

2008-12-15 Thread Joel Hedlund
I'm having a very hard time explaining why this snippet *sometimes* raises KeyError: snippet: print type(self.pool) for frag in self.pool.keys(): if frag is fragment_info: print "the fragment_info *is* in the pool", hash(frag), hash(fragment_info), hash(frag) == hash(fragment_info)

Re: dict problem

2006-10-30 Thread Ben Finney
Alistair King <[EMAIL PROTECTED]> writes: > heavy = raw_input("\n\n@@\n\nPlease enter the heaviest > atom for which you obtained percentage values for, but not Oxygen, eg, > 'C', 'N', 'S', 'Br'...: ") > > print DSvalues > > def updateDS1v(Fxas, x): > if Fxas != 0: > value = DSvalue

Re: dict problem

2006-10-30 Thread Alistair King
Peter Otten wrote: > Alistair King wrote: > > >> the code works great now. I know these things are quite simple to learn >> from books etc.. but i would be lost without this mailinglist, from lack >> of time. Hopefully soon i can give something more complicated. >> I ended up doing the dictionar

Re: dict problem

2006-10-30 Thread Peter Otten
Alistair King wrote: > the code works great now. I know these things are quite simple to learn > from books etc.. but i would be lost without this mailinglist, from lack > of time. Hopefully soon i can give something more complicated. > I ended up doing the dictionary formatting properly and the n

Re: dict problem

2006-10-30 Thread Alistair King
Fredrik Lundh wrote: > Alistair King wrote: > > >> Is there any other way of removing double and single quotes from a >> number, as a string, to give the float value again? >> > > help(str) describes what you can do with a string (an object of type > 'str', that is). among the methods lis

Re: dict problem

2006-10-30 Thread Fredrik Lundh
Alistair King wrote: > Is there any other way of removing double and single quotes from a > number, as a string, to give the float value again? help(str) describes what you can do with a string (an object of type 'str', that is). among the methods listed, you'll find: > | strip(...) > |

dict problem

2006-10-30 Thread Alistair King
Ben Finney wrote: > Alistair King <[EMAIL PROTECTED]> writes: > > >> Ben Finney wrote: >> >>> Even better, work on a minimal program to do nothing but reproduce >>> the unexpected behaviour. If you get to such a program and still >>> don't understand, then post it here so others can run it

Re: dict problem

2006-10-25 Thread Ben Finney
Alistair King <[EMAIL PROTECTED]> writes: > Ben Finney wrote: > > Even better, work on a minimal program to do nothing but reproduce > > the unexpected behaviour. If you get to such a program and still > > don't understand, then post it here so others can run it > > themselves and explain. > ive c

Re: dict problem

2006-10-25 Thread Alistair King
Ben Finney wrote: > "Jon Clements" <[EMAIL PROTECTED]> writes: > > >> We're still in the dark as to what you're trying to do, try >> describing something like: "for each element there is an associated >> 'F' value. For each element in an existing molecule I wish to change >> the number of 'whate

Re: dict problem

2006-10-25 Thread Ben Finney
"Jon Clements" <[EMAIL PROTECTED]> writes: > We're still in the dark as to what you're trying to do, try > describing something like: "for each element there is an associated > 'F' value. For each element in an existing molecule I wish to change > the number of 'whatever' to be 'whatever' + my 'F'

Re: dict problem

2006-10-25 Thread Jon Clements
Alistair King wrote: > Jon Clements wrote: > > > > Alistair King wrote: > > > > > > > > > >> >> Hi, > >> >> > >> >> ive been trying to update a dictionary containing a molecular formula, > >> >> but seem to be getting this error: > >> >> > >> >> > >> >> Traceback (most recent call last): > >> >>

dict problem

2006-10-25 Thread Alistair King
Jon Clements wrote: > > Alistair King wrote: > > > > > >> >> Hi, >> >> >> >> ive been trying to update a dictionary containing a molecular formula, >> >> but seem to be getting this error: >> >> >> >> >> >> Traceback (most recent call last): >> >> File "DS1excessH2O.py", line 242, in ? >>

Re: dict problem

2006-10-25 Thread Jon Clements
Alistair King wrote: > Hi, > > ive been trying to update a dictionary containing a molecular formula, but > seem to be getting this error: > > > Traceback (most recent call last): > File "DS1excessH2O.py", line 242, in ? > updateDS1v(FCas, C, XDS) > NameError: name 'C' is not defined > > d

Re: dict problem

2006-10-25 Thread Peter Otten
Alistair King wrote: > Hi, > > ive been trying to update a dictionary containing a molecular formula, but > seem to be getting this error: > > > Traceback (most recent call last): > File "DS1excessH2O.py", line 242, in ? > updateDS1v(FCas, C, XDS) > NameError: name 'C' is not defined > >

Re: dict problem

2006-10-25 Thread Roberto Bonvallet
Roberto Bonvallet wrote: > Alistair King wrote: >> DS1v = {'C': 6, 'H': 10, 'O': 5} > > Try DS1v['C'] instead of DS1v[C]. > updateDS1v(FCas, C, XDS) > updateDS1v(FHas, H, XDS) > updateDS1v(FOas, O, XDS) > updateDS1v(FNas, N, XDS) > updateDS1v(FSas, S, XDS) > updateDS1v(FClas, Cl, XDS) > updateDS1

Re: dict problem

2006-10-25 Thread Roberto Bonvallet
Alistair King wrote: > Hi, > > ive been trying to update a dictionary containing a molecular formula, but > seem to be getting this error: > > > Traceback (most recent call last): > File "DS1excessH2O.py", line 242, in ? >updateDS1v(FCas, C, XDS) > NameError: name 'C' is not defined > > d

dict problem

2006-10-25 Thread Alistair King
Hi, ive been trying to update a dictionary containing a molecular formula, but seem to be getting this error: Traceback (most recent call last): File "DS1excessH2O.py", line 242, in ? updateDS1v(FCas, C, XDS) NameError: name 'C' is not defined dictionary is: DS1v = {'C': 6, 'H': 10, 'O

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] > e

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-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):

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 ? safe_e

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'

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

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 > 'Un

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: > 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

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: a dict problem

2005-05-28 Thread Steven Bethard
Benji York wrote: > I'll extrapolate from your message that you want to get the values of > the dict in sorted order. If so, here's how: > > >>> d = {'a': 1, 'b': 2, 'c':3} > >>> d > {'a': 1, 'c': 3, 'b': 2} > >>> v = d.values() > >>> v > [1, 3, 2] > >>> v.sort() > >>> v > [1, 2, 3] Or in

Re: a dict problem

2005-05-28 Thread Benji York
cheng wrote: > hi all..it a problem about dict: > > print target, dict[target] > > get output: > > keyword > {page3.html, page2.html, page1.html} > > is it some ways to change it to: > > keyword > {page1.html, page2.html, page3.html} First, I would recommend you always post actual cod

a dict problem

2005-05-28 Thread cheng
hi all..it a problem about dict: print target, dict[target] get output: keyword {page3.html, page2.html, page1.html} is it some ways to change it to: keyword {page1.html, page2.html, page3.html} -- http://mail.python.org/mailman/listinfo/python-list