Quick Tip: Python's noop Equivalent

| No Comments | Bookmark and Share

Python can't deal with empty code blocks, which may arise if you want to stub out a block but leave the implementation for later. If you have one in your code, the interpreter will give the following error:

  File "foo.py", line 1
    if (foo == bar):
     ^
IndentationError: expected an indented block

In this case, you can use the pass operator which will do nothing but take up a line, resulting in the following code:

if (foo == bar):
    pass #TODO
else:
    print "nothing to do!"

Leave a comment

About this Entry

This page contains a single entry by Drew Stephens published on November 30, 2007 6:52 AM.

mdadm Isn't Someone You Want to Hear From was the previous entry in this blog.

Perl, Python and Ruby is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 5.1