krish – 起死回生 [Wake up from death & return to life.]

December 4, 2008

Document your python functions

Filed under: Programming — krish @ 12:19 am
Tags: , ,

Many people tend to ignore commenting and documenting the code they write. The small amounts of invested time can make life ease for others; especially if you are a crappy coder like me! 🙂

In python, to document your functions, give it a doc string. Doc strings are the first triple quoted string you’d want in a function.

test.py

def mySmallFunction(myParams):
      """ Does nothing. Just a time consuming run. """
      return ";)"

if __name__ == "__main__":
     myParams = {"test.py":"dummy"}
     print mySmallFunction(myParams)

In the python interpreter, doc strings can be accessed by calling attribute __doc___

>>> import test
>>> test.mySmallFunction.__doc__
' Does nothing. Just a time consuming run. '

Advertisements

1 Comment »

  1. Well, every function needs to be documented, not only Python Functions 😛 . So your title will look better if you says “Document your Functions” ..

    Just a nit but the idea of documentation is quite fundamental to a good programmer. Knuth said once “programs should be written to be read by humans and incidently for machines to excute”, after my two an dhalf years of expereince in this field, I can see how damn right he is.

    Comment by arnuld — February 16, 2009 @ 5:44 pm


RSS feed for comments on this post. TrackBack URI

Please leave a Reply / Discuss this topic here :)

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Blog at WordPress.com.

The Male Factor

On behalf of the ignored gender

Rough Draft

by Atteris Amarth and Darrek Ringo

The Kochi Post.

Read by all + Influenced by none

JumboMake

A signature of Kiran

SAAYAM CHEDDAM FOUNDATION

This blog is just for additional and extension share of it's main frames. No activity is planned from here

krish - 起死回生 [Wake up from death & return to life.]

Get a sneak peek into krish's life, work and passion.

WordPress.com

WordPress.com is the best place for your personal blog or business site.

A Tale of Two and a Half

Monika Amita Bakshi

%d bloggers like this: