Remove outdate FAQ content

This commit is contained in:
Antoine Pitrou 2011-12-03 22:19:55 +01:00
parent c5b266efb5
commit f35204055e
1 changed files with 8 additions and 32 deletions

View File

@ -901,11 +901,11 @@ There are various techniques.
Is there an equivalent to Perl's chomp() for removing trailing newlines from strings? Is there an equivalent to Perl's chomp() for removing trailing newlines from strings?
------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------
Starting with Python 2.2, you can use ``S.rstrip("\r\n")`` to remove all You can use ``S.rstrip("\r\n")`` to remove all occurrences of any line
occurrences of any line terminator from the end of the string ``S`` without terminator from the end of the string ``S`` without removing other trailing
removing other trailing whitespace. If the string ``S`` represents more than whitespace. If the string ``S`` represents more than one line, with several
one line, with several empty lines at the end, the line terminators for all the empty lines at the end, the line terminators for all the blank lines will
blank lines will be removed:: be removed::
>>> lines = ("line 1 \r\n" >>> lines = ("line 1 \r\n"
... "\r\n" ... "\r\n"
@ -916,15 +916,6 @@ blank lines will be removed::
Since this is typically only desired when reading text one line at a time, using Since this is typically only desired when reading text one line at a time, using
``S.rstrip()`` this way works well. ``S.rstrip()`` this way works well.
For older versions of Python, there are two partial substitutes:
- If you want to remove all trailing whitespace, use the ``rstrip()`` method of
string objects. This removes all trailing whitespace, not just a single
newline.
- Otherwise, if there is only one line in the string ``S``, use
``S.splitlines()[0]``.
Is there a scanf() or sscanf() equivalent? Is there a scanf() or sscanf() equivalent?
------------------------------------------ ------------------------------------------
@ -1042,15 +1033,8 @@ list, deleting duplicates as you go::
else: else:
last = mylist[i] last = mylist[i]
If all elements of the list may be used as dictionary keys (i.e. they are all If all elements of the list may be used as set keys (i.e. they are all
hashable) this is often faster :: :term:`hashable`) this is often faster ::
d = {}
for x in mylist:
d[x] = 1
mylist = list(d.keys())
In Python 2.5 and later, the following is possible instead::
mylist = list(set(mylist)) mylist = list(set(mylist))
@ -1420,15 +1404,7 @@ not::
C.count = 314 C.count = 314
Static methods are possible since Python 2.2:: Static methods are possible::
class C:
def static(arg1, arg2, arg3):
# No 'self' parameter!
...
static = staticmethod(static)
With Python 2.4's decorators, this can also be written as ::
class C: class C:
@staticmethod @staticmethod