]> granicus.if.org Git - python/commitdiff
Merged revisions 83328,83341 via svnmerge from
authorGeorg Brandl <georg@python.org>
Sun, 1 Aug 2010 19:21:26 +0000 (19:21 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 1 Aug 2010 19:21:26 +0000 (19:21 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r83328 | raymond.hettinger | 2010-07-31 12:14:41 +0200 (Sa, 31 Jul 2010) | 1 line

  Document how to change OrderedDict update order from first to last.
........
  r83341 | georg.brandl | 2010-07-31 13:40:07 +0200 (Sa, 31 Jul 2010) | 1 line

  #9430: document timedelta str() and repr().
........

Doc/library/collections.rst
Doc/library/datetime.rst

index 14539be6cc276985d0fd9283727fed88234a0c88..018f92ae331e3d9eb057560e9d5c2eb7e2e4a379 100644 (file)
@@ -958,3 +958,15 @@ in conjuction with sorting to make a sorted dictionary::
 The new sorted dictionaries maintain their sort order when entries
 are deleted.  But when new keys are added, the keys are appended
 to the end and the sort is not maintained.
+
+It is also straight-forward to create an ordered dictionary variant
+that the remembers the order the keys were *last* inserted.
+If a new entry overwrites an existing entry, the
+original insertion position is changed and moved to the end::
+
+    class LastUpdatedOrderedDict(OrderedDict):
+        'Store items is the order the keys were last added'
+        def __setitem__(self, key, value):
+            if key in self:
+                del self[key]
+            OrderedDict.__setitem__(self, key, value)
index 53d416af6e27452b589be08d11b64c02f0a14379..21a2b640f0fcc508cde3f92304219b59c315d0d3 100644 (file)
@@ -235,6 +235,14 @@ Supported operations:
 | ``abs(t)``                     | equivalent to +\ *t* when ``t.days >= 0``, and|
 |                                | to -*t* when ``t.days < 0``. (2)              |
 +--------------------------------+-----------------------------------------------+
+| ``str(t)``                     | Returns a string in the form                  |
+|                                | ``[D day[s], ][H]H:MM:SS[.UUUUUU]``, where D  |
+|                                | is negative for negative ``t``. (5)           |
++--------------------------------+-----------------------------------------------+
+| ``repr(t)``                    | Returns a string in the form                  |
+|                                | ``datetime.timedelta(D[, S[, U]])``, where D  |
+|                                | is negative for negative ``t``. (5)           |
++--------------------------------+-----------------------------------------------+
 
 Notes:
 
@@ -250,6 +258,16 @@ Notes:
 (4)
    -*timedelta.max* is not representable as a :class:`timedelta` object.
 
+(5)
+  String representations of :class:`timedelta` objects are normalized
+  similarly to their internal representation.  This leads to somewhat
+  unusual results for negative timedeltas.  For example:
+
+  >>> timedelta(hours=-5)
+  datetime.timedelta(-1, 68400)
+  >>> print(_)
+  -1 day, 19:00:00
+
 In addition to the operations listed above :class:`timedelta` objects support
 certain additions and subtractions with :class:`date` and :class:`datetime`
 objects (see below).