Keeping it Small and Simple


Python doc strings: of course you can, but don’t

Filed under: Python Programming — Tags: , , — Lorenzo E. Danielsson @ 20:46

Just because somebody asked, I had to show that it can be done. But no, doc strings are not the place to store static data.

 1 #! /usr/bin/env python
 3 # Foo! Don’t do this.
 4 # Author: Lorenzo E. Danielsson <danielsson +dot+ lorenzo [at] gmail *dot* com>
 6 def bleech():
 7     "0"
 8     bleech.__doc__ = str(int(bleech.__doc__) + 1)
 9     print "I have been called %s time%s." % (
10             bleech.__doc__,
11             bleech.__doc__ != ‘1‘ and ‘s‘ or ”)
13 for i in range(10):
14     bleech()

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: