Python Forum
where is this documented?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
where is this documented?
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
https://docs.python.org/3/library/stdtyp...ict.update
Reply
#3
According to the documentation, the behavior is the same as foo = None.
Reply
#4
(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).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
If you read carefully, typing pydoc3 dict.update in a terminal gives the same information.
Reply
#6
yes, it sure does. i was not aware of this way to get python documentation.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#7
If have a "cool" editor mouse over update Wink
[Image: dRd3Aj.jpg]
Reply
#8
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#9
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).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  issubclass() not as documented Skaperen 19 7,629 Mar-15-2021, 04:58 PM
Last Post: nilamo
  format spec %b is documented but does not work Skaperen 13 10,469 Jul-31-2017, 09:21 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020