1 / 11

Python Documentation

Python Documentation. Fran Fitzpatrick. Overview. Comments Documentation Strings Pydoc. Comments. Python Comments Symbol: # Block Comments Inline Comments. Comments. import string, sys # If no arguments were given, print a helpful message if len(sys.argv)==1:

tom
Download Presentation

Python Documentation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Python Documentation Fran Fitzpatrick

  2. Overview • Comments • Documentation Strings • Pydoc

  3. Comments • Python Comments Symbol: # • Block Comments • Inline Comments

  4. Comments import string, sys # If no arguments were given, print a helpful message if len(sys.argv)==1: print 'Usage: celsius temp1 temp2 ...' sys.exit(0) # Loop over the arguments for i in sys.argv[1:]: try: fahrenheit=float(string.atoi(i)) except string.atoi_error: #ascii to integer error print repr(i), "not a numeric value" else: celsius=(fahrenheit-32)*5.0/9.0 print '%i\260F = %i\260C' % (int(fahrenheit), int(celsius+.5))

  5. Documentation Strings • Shortened to “Docstrings” • Symbol: “ ” ” (three quotes) • Use for all public: • Functions • Methods • Modules • Classes • Why?

  6. Documentation Strings from myro import * init("/dev/tty.scribbler") def avoid(): """ This is a simple function that will simple make the robot wander around avoiding all obstacles. If it encounters an obstacle, it will back up and turn the other way. """ while True: if getObstacle("right"): backward(1, .1) turnLeft(.7,.1) elif getObstacle("left"): backward(1,.1) turnRight(.7,.1) else: forward(1) wait(.1)

  7. Pydoc • Automatic Doc Generation • Command line options: • pydoc <module> -- man-like command • pydoc -w <module> -- write HTML file to current directory • pydoc -k <arg> -- will search synopsis of all available modules for the search string ‘arg’ • pydoc -p <port> -- will start a webserver on specified port

  8. Pydoc # Here are a few programs that would work well # for our robot. def avoid(): """ This is a simple function that will simple make the robot wander around avoiding all obstacles. If it encounters an obstacle, it will back up and turn the other way. """ while True: if getObstacle("right"): backward(1, .1) turnLeft(.7,.1) elif getObstacle("left"): backward(1,.1) turnRight(.7,.1) else: forward(1) wait(.1)

  9. Pydoc >>> import robot >>> help(robot) Help on module robot: NAME robot FILE /Volumes/THAWSPACE/Fran/robot.py DESCRIPTION # Here are a few programs that would work well # for our robot. FUNCTIONS avoid() This is a simple function that will simple make the robot wander around avoiding all obstacles. If it encounters an obstacle, it will back up and turn the other way.

  10. Summary • Comments • Documentation Strings • Pydoc

  11. Questions?

More Related