Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f3520405
Commit
f3520405
authored
Dec 03, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove outdate FAQ content
parent
c5b266ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
32 deletions
+8
-32
Doc/faq/programming.rst
Doc/faq/programming.rst
+8
-32
No files found.
Doc/faq/programming.rst
View file @
f3520405
...
...
@@ -901,11 +901,11 @@ There are various techniques.
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
occurrences of any line terminator from the end of the string ``S`` without
removing other trailing whitespace. If the string ``S`` represents more than
one line, with several empty lines at the end, the line terminators for all the
b
lank lines will b
e removed::
You can use ``S.rstrip("\r\n")`` to remove all occurrences of any line
terminator from the end of the string ``S`` without removing other trailing
whitespace. If the string ``S`` represents more than one line, with several
empty lines at the end, the line terminators for all the blank lines will
be removed::
>>> lines = ("line 1 \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
``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?
------------------------------------------
...
...
@@ -1042,15 +1033,8 @@ list, deleting duplicates as you go::
else:
last = mylist[i]
If all elements of the list may be used as dictionary keys (i.e. they are all
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::
If all elements of the list may be used as set keys (i.e. they are all
:term:`hashable`) this is often faster ::
mylist = list(set(mylist))
...
...
@@ -1420,15 +1404,7 @@ not::
C.count = 314
Static methods are possible since Python 2.2::
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 ::
Static methods are possible::
class C:
@staticmethod
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment