Programming Principles in Python (CSCI 503)
Programming Principles in Python (CSCI 503)
Arrays
Dr. David Koop
D. Koop, CSCI 503, Spring 2021
if
if
if
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
D. Koop, CSCI 503, Spring 2021
[RealPython]
2
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
D. Koop, CSCI 503, Spring 2021
4
if
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
D. Koop, CSCI 503, Spring 2021
[RealPython]
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
- numpy numeric python
- programming principles in python csci 503
- numpy reference nus computing
- numpy tutorial
- programming principles in python csci 503 490
- numerical python cineca
- introduction chapter to numpy national council of educational
- numpy reference university of wisconsin madison
- numpy reference scipy
- with data analytics machine learning using python r
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