Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python Documentation Fran Fitzpatrick. Overview  Comments  Documentation Strings  Pydoc  Comments  Documentation Strings  Pydoc.

Similar presentations


Presentation on theme: "Python Documentation Fran Fitzpatrick. Overview  Comments  Documentation Strings  Pydoc  Comments  Documentation Strings  Pydoc."— Presentation transcript:

1 Python Documentation Fran Fitzpatrick

2 Overview  Comments  Documentation Strings  Pydoc  Comments  Documentation Strings  Pydoc

3 Comments  Python Comments Symbol: #  Block Comments  Inline 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?  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 -- man-like command  pydoc -w -- write HTML file to current directory  pydoc -k -- will search synopsis of all available modules for the search string ‘arg’  pydoc -p -- will start a webserver on specified port  Automatic Doc Generation  Command line options:  pydoc -- man-like command  pydoc -w -- write HTML file to current directory  pydoc -k -- will search synopsis of all available modules for the search string ‘arg’  pydoc -p -- 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  Comments  Documentation Strings  Pydoc

11


Download ppt "Python Documentation Fran Fitzpatrick. Overview  Comments  Documentation Strings  Pydoc  Comments  Documentation Strings  Pydoc."

Similar presentations


Ads by Google