Python Forum
where is this documented? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: where is this documented? (/thread-8362.html)



where is this documented? - Skaperen - Feb-17-2018

the following code:

foo = {}.update(os.environ)
has a behavior that i have been unable to find documentation that describes (assuming import os has been done). does anyone know if such documentation exists and where that documentation can be found? i have PDF documentation for python version 3.5.2 but a reference in an HTML document of 3.4 or later should be good enough.


RE: where is this documented? - Larz60+ - Feb-17-2018

https://docs.python.org/3/library/stdtypes.html?highlight=dict%20update#dict.update


RE: where is this documented? - Gribouillis - Feb-17-2018

According to the documentation, the behavior is the same as foo = None.


RE: where is this documented? - Skaperen - Feb-18-2018

(Feb-17-2018, 01:32 PM)Gribouillis Wrote: According to the documentation, the behavior is the same as foo = None.

my documentation (PDF letter format for 3.5.2) didn't give that information. maybe i need to switch back to the HTML documentation (been using PDF for 3+ years).


RE: where is this documented? - Gribouillis - Feb-18-2018

If you read carefully, typing pydoc3 dict.update in a terminal gives the same information.


RE: where is this documented? - Skaperen - Feb-19-2018

yes, it sure does. i was not aware of this way to get python documentation.


RE: where is this documented? - snippsat - Feb-19-2018

If have a "cool" editor mouse over update Wink
[Image: dRd3Aj.jpg]


RE: where is this documented? - DeaD_EyE - Feb-19-2018

foo = {}.update(os.environ)
foo is None because the method update returns None.
You can do this technique with data types, which returns a new copy of them selfs if mutated (str does this).

It's the same pitfall like this:
sorted_list = [1,4,5,6,7,3,2].sort()
list.sort() makes an inline sort (mutating the object itself) and returns None.


RE: where is this documented? - Skaperen - Feb-20-2018

i guess i am just used to methods that returned something useful. i did know about .sort but didn't think of it as another case. i usually use sorted(iterable).