Possible dictionary bug?
Hi all I try these code in a Python Script: A = dict() A['Example'] = 1 return A.update({'DoesItWorks': 'Perhaps'}) In the python interpreter it works fine but in the python script returns None Can anyone reproduce the problem? Thanks!!!!!
A.update(...) should have a value of None as it should. I would suspect the test program rather than the interpreter. Can you post exactly what fails in bopth instances? On Mon, 23 Aug 2004, Garito wrote:
Hi all
I try these code in a Python Script:
A = dict() A['Example'] = 1
return A.update({'DoesItWorks': 'Perhaps'})
In the python interpreter it works fine but in the python script returns None
Can anyone reproduce the problem?
Thanks!!!!!
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
----- Original Message ----- From: "Garito" <garito@sistes.net>
I try these code in a Python Script:
A = dict() A['Example'] = 1
return A.update({'DoesItWorks': 'Perhaps'})
In the python interpreter it works fine but in the python script returns None
Can anyone reproduce the problem?
In a python script try: A = {} A['example'] = 1 A.update({'DoesItWork' : 'yes'}) return A HTH Jonathan
On Mon, Aug 23, 2004 at 06:48:07PM +0200, Garito wrote:
Hi all
I try these code in a Python Script:
A = dict() A['Example'] = 1
return A.update({'DoesItWorks': 'Perhaps'})
In the python interpreter it works fine
that's where you're mistaken. dict.update always returns None. See the python library documentation. This is typical of methods that change mutable objects, such as list.sort, list.append, or list.extend. A notable exception is list.pop which both removes an item and returns it. -- Paul Winkler http://www.slinkp.com
Paul Winkler wrote:
On Mon, Aug 23, 2004 at 06:48:07PM +0200, Garito wrote:
Hi all
I try these code in a Python Script:
A = dict() A['Example'] = 1
return A.update({'DoesItWorks': 'Perhaps'})
In the python interpreter it works fine
that's where you're mistaken. dict.update always returns None. See the python library documentation. This is typical of methods that change mutable objects, such as list.sort, list.append, or list.extend. A notable exception is list.pop which both removes an item and returns it.
Uups!!!! hehe my neuron seems to be drunk Sorry!!! Thank you Paul!!!
Garito wrote:
Hi all
I try these code in a Python Script:
A = dict() A['Example'] = 1
return A.update({'DoesItWorks': 'Perhaps'})
It is in fact a feature. It returns None to remind you that it changes a mutable object. Python does this a lot. The example you will probably meet most often in the wild, is the list.sort() method, that doesn't return the list either. I know that that one has fooled med a couple of times in the past. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science
participants (5)
-
Dennis Allison -
Garito -
Jonathan Hobbs -
Max M -
Paul Winkler