Keeping it Small and Simple

2008.03.20

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
 2
 3 # Foo! Don’t do this.
 4 # Author: Lorenzo E. Danielsson <danielsson +dot+ lorenzo [at] gmail *dot* com>
 5
 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 ”)
12
13 for i in range(10):
14     bleech()

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.