Programming Principles in Python (CSCI 503)
Programming Principles in Python (CSCI 503)
Arrays
Dr. David Koop
D. Koop, CSCI 503, Spring 2021
Modules and Packages
? Python allows you to import code from other les, even your own
? A module is a collection of de nitions
? A package is an organized collection of modules
? Modules can be
- a separate python le
- a separate C library that is written to be used with Python
- a built-in module contained in the interpreter
- a module installed by the user (via conda or pip)
? All types use the same import syntax
[RealPython]
fi
2
fi
fi
D. Koop, CSCI 503, Spring 2021
What is the purpose of having modules or packages?
? Code reuse: makes life easier because others have written solutions to
various problems
? Generally forces an organization of code that works together
? Standardizes interfaces; easier maintenance
? Encourages robustness, testing code
? This does take time so don't always create a module or package
- If you're going to use a method once, it's not worth putting it in a module
- If you're using the same methods over and over in (especially in different
projects), a module or package makes sense
D. Koop, CSCI 503, Spring 2021
3
Importing modules
?
?
?
?
import
import as
from import
from import as ,
? import imports from the top, from import imports "inner" names
? Need to use the quali ed names when using import (foo.bar.mymethod)
? as clause renames the imported name
fi
D. Koop, CSCI 503, Spring 2021
4
Namespaces
? Namespace is basically a dictionary with
names and their values
? Accessing namespaces
- __builtins__, globals(), locals()
? Examine contents of a namespace:
dir()
? Python checks for a name in the sequence:
local, enclosing, global, builtins
? To access names in outer scopes, use
global (global) and nonlocal (enclosing)
declarations
[RealPython]
D. Koop, CSCI 503, Spring 2021
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- programming principles in python csci 503
- arrays definition example of an array named a of 5
- introduction to numpy and opencv
- 6 003 signal processing
- turn 2d array into 3d
- release 0 1 1 andrew straw florian finkernagel
- math 3040 introduction to numpy scipy and plotting
- introduction chapter to numpy
- homework 3 part 1 carnegie mellon university
Related searches
- financial management principles in healthcare
- financial management principles in health
- financial principles in healthcare
- finance principles in health care
- adult learning principles in nursing
- ethical principles in the workplace
- 7 ethical principles in nursing
- personal principles in life
- ethical principles in nursing definitions
- 4 ethical principles in medicine
- basic ethical principles in research
- basic ethical principles in business