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

Slides:



Advertisements
Similar presentations
This Week More Types boolean string Modules print statement Writing programs if statement Type boolean.
Advertisements

Python Basics: Statements Expressions Loops Strings Functions.
PYTHON FRUITFUL FUNCTIONS CHAPTER 6 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Intro to Robots Robots are Everywhere. Intro to Robots Various robots in use today lawnmower pet baby seal for convalescents gutter cleaner home security.
Intro to Robots Lab 2. Intro to Robots Defining Functions: Define a function and watch its behaviour A useful function is wait(SECONDS) that causes the.
James Tam Introduction To Files In Python In this section of notes you will learn how to read from and write to files in your programs.
CSC 9010: Natural Language Processing
Writing Solid Code Introduction to Python. Program 1 python -c "print 'Hello World' “ python -c "import time; print time.asctime()“ Start an interactive.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
Taking Pictures Sec 9-9 Web Design. Objectives The student will: Know how command the scribbler robot to take a picture. Know how to display the picture.
Python.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
Python Basic Syntax. Basic Syntax - First Program 1 All python files will have extension.py put the following source code in a test.py file. print "Hello,
Guide to Programming with Python Chapter Seven (Part 1) Files and Exceptions: The Trivia Challenge Game.
STRINGS CMSC 201 – Lab 3. Overview Objectives for today's lab:  Obtain experience using strings in Python, including looping over characters in strings.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering –Intro to the Robotics –Introducing the IC –Discuss.
Invasion Percolation: Assembly Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Chapter 24 Exception CSC1310 Fall Exceptions Exceptions Exceptions are events that can modify the flow or control through a program. They are automatically.
Hey, Ferb, I know what we’re gonna do today! Aims: Use formatted printing. Use the “while” loop. Understand functions. Objectives: All: Understand and.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 5 Function Interfaces 4/18/09 Python Mini-Course: Day 2 - Lesson 5 1.
How to link the robot and the computer (Bluetooth) How to turn on and off How to connect the adaptor Fluke card connection Sec Getting Started How.
Libraries Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Python Functions.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Cem Sahin CS  There are two distinguishable kinds of errors: Python's Errors Syntax ErrorsExceptions.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
9/28/2015BCHB Edwards Basic Python Review BCHB Lecture 8.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
CHAPTER 3 Decisions and Repetition. A few new constants Constants so far:  Strings  Numbers  integer  float Boolean constants: [On board]
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
Guide to Programming with Python Chapter Seven Files and Exceptions: The Trivia Challenge Game.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
11. EXCEPTION HANDLING Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Python Let’s get started!.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
CS2021 Python Programming Week 3 Systems Programming PP-Part II.
Lecture 4 Python Basics Part 3.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
12. MODULES Rocky K. C. Chang November 6, 2015 (Based on from Charles Dierbach. Introduction to Computer Science Using Python and William F. Punch and.
CIT 590 Intro to Programming Files etc. Agenda Files Try catch except A module to read html off a remote website (only works sometimes)
CIT 590 Intro to Programming Lecture 6. Vote in the doodle poll so we can use some fancy algorithm to pair you up You.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Web Database Programming Using PHP
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Python Let’s get started!.
What you asked me to teach…
Web Database Programming Using PHP
Software Engineering for Data Scientists
Style Generally style is built into Python, as it demands indents. However, good Python style is set out in PEP8:
Pre-processor Directives
While loops Genome 559: Introduction to Statistical and Computational Genomics Prof. William Stafford Noble.
Topics Introduction to File Input and Output
Introduction to Python
Basic Python Review BCHB524 Lecture 8 BCHB524 - Edwards.
Copyright © – Curt Hill Bash Flow of Control Copyright © – Curt Hill.
Python programming exercise
Rocky K. C. Chang 15 November 2018 (Based on Dierbach)
Advanced Python Concepts: Exceptions
Basic Python Review BCHB524 Lecture 8 BCHB524 - Edwards.
While loops Genome 559: Introduction to Statistical and Computational Genomics Prof. William Stafford Noble.
Advanced Python Concepts: Exceptions
Topics Introduction to File Input and Output
Presentation transcript:

Python Documentation Fran Fitzpatrick

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

Comments  Python Comments Symbol: #  Block Comments  Inline 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: 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))

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?

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)

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

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)

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.

Summary  Comments  Documentation Strings  Pydoc  Comments  Documentation Strings  Pydoc