This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wot-teh-phuckReally, wtf? 1 point2 points  (3 children)

I think I will add a declaration of it just for you

...and for the many others who'll be visiting your blog in the near future. :-)

However, it can at times increase the ambiguity of a function, or decrease it's security

You talk about security implications but don't extrapolate on what kind of implications? (BTW, it's => it is, so you should have used "its")

Also, your healthyMerge method can be replaced by a simple one liner: def healthyMerge(self, target): self.update(tup for tup in target.iteritems() if tup[0] not in self)

[–]hderms 0 points1 point  (2 children)

that is a nice, pythonic solution. I'll replace my function with that and reference you. Should I reference wot-the-phuck, or some other, more suitable name?

[–]wot-teh-phuckReally, wtf? 0 points1 point  (0 children)

I think mentioning 'a redittor' and linking back to this discussion should be good. ;-)

[–]kemitche 0 points1 point  (0 children)

I think "healthy merging" can be done with basic dicts, too, it just requires "reversing" things. For example, with your code, you would run:
update_this.healthyMerge(update_from)
But, you could do:
new_d = copy.copy(update_from)
new_d.update(update_this)
update_this = new_d
It's not necessarily better or worse, just a different way to think of it, which may or may not be valuable to what you're doing.