An Introduction to Python Part IV - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

An Introduction to Python Part IV

Description:

comments In-file documentation. The dir function Lists of attributes ... Function Doctring comment. 5/19/05. Introduction to Python Part IV. 8. Debugging ... – PowerPoint PPT presentation

Number of Views:97
Avg rating:3.0/5.0
Slides: 10
Provided by: lanct
Category:

less

Transcript and Presenter's Notes

Title: An Introduction to Python Part IV


1
An Introduction to Python Part IV
  • Dr. Nancy Warter-Perez
  • May 19, 2005

2
Overview
  • Scopes
  • Modules
  • Doc Strings
  • Debugging

3
Scopes
  • Scopes divine the visibility of a variable
  • Variables defined outside of a function are
    visible to all of the functions within a module
    (file)
  • Variables defined within a function are local to
    that function
  • To make a variable that is defined within a
    function global, use the global keyword

Ex 2 x 5 def fnc() global x x 2
print x, fnc() print x gtgtgt 2 2
Ex 1 x 5 def fnc() x 2 print
x, fnc() print x gtgtgt 2 5
4
Modules
  • Why use?
  • Code reuse
  • System namespace partitioning (avoid name
    clashes)
  • Implementing shared services or data
  • How to structure a Program
  • One top-level file
  • Main control flow of program
  • Zero or more supplemental files known as modules
  • Libraries of tools

5
Modules - Import
  • Import used to gain access to tools in modules
  • Ex
  • contents of file b.py
  • def spam(text)
  • print text, 'spam'
  • contents of file a.py
  • import b
  • b.spam('gumby')

6
Python Documentation Sources
  • comments In-file documentation
  • The dir function Lists of attributes
    available on objects
  • Docstrings__doc__ In-file documentation
  • attached to objects

7
Dir and DocString Example
  • Ex b.py
  • Internal comment
  • """Module Docstring comment """
  • def fn()
  • """Function Docstring comment """
  • gtgtgt import b
  • gtgtgt dir(b)
  • '__builtins__', '__doc__', '__file__',
    '__name__', 'fn'
  • gtgtgt print b.__doc__
  • Module Docstring comment
  • gtgtgt print b.fn.__doc__
  • Function Doctring comment

8
Debugging
  • Can use print statements to manually debug
  • Can use debugger in PythonWin
  • In Class Example

9
Project Teams and Presentation Assignments
  • Base Project (Global Alignment)
  • Extension 1 (Local Alignment)
  • Extension 2 (Ends-Free Global Alignment)
  • Extension 3 (Affine Gap Penalty)
  • Extension 4 (Database)
Write a Comment
User Comments (0)
About PowerShow.com