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
a8bb5506
Commit
a8bb5506
authored
Nov 06, 2008
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4247: add "pass" examples to tutorial.
parent
692c2f8f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
Doc/tutorial/controlflow.rst
Doc/tutorial/controlflow.rst
+33
-0
No files found.
Doc/tutorial/controlflow.rst
View file @
a8bb5506
...
...
@@ -166,6 +166,39 @@ required syntactically but the program requires no action. For example::
... pass # Busy-wait for keyboard interrupt (Ctrl+C)
...
This is commonly used for creating minimal classes like with exceptions, or
for skipping unwanted exceptions::
>>> class ParserError(Exception):
... pass
...
>>> try:
... import audioop
... except ImportError:
... pass
...
Another place it can be used is as a place-holder for a function or
conditional body when you are working on new code, allowing you to keep
thinking at a more abstract level. However, as :keyword:`pass` is silently
ignored, a better choice may be to raise a :exc:`NotImplementedError`
exception::
>>> def initlog(*args):
... raise NotImplementedError # Open logfile if not already open
... if not logfp:
... raise NotImplementedError # Set up dummy log back-end
... raise NotImplementedError('Call log initialization handler')
...
If :keyword:`pass` were used here and you later ran tests, they may fail
without indicating why. Using :exc:`NotImplementedError` causes this code
to raise an exception, allowing you to tell exactly where code that you
need to complete is. Note the two call styles of the exceptions above.
The comment style is useful in that when you remove the exception you can
easily leave the comment, which ideally would be a good description for
the block of code the exception is a placeholder for. The call-style
will raise a more useful exception however.
.. _tut-functions:
...
...
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