Programming Principles in Python (CSCI 503)

Programming Principles in Python (CSCI 503)

Modules and Packages

Dr. David Koop

D. Koop, CSCI 503, Spring 2021

Command Line Interfaces (CLIs)

? Prompt:

- $

? Commands

- $ cat

- $ git init

? Arguments/Flags: (options)

- $ python -h

- $ head -n 5

- $ git branch fix-parsing-bug

D. Koop, CSCI 503, Spring 2021

2

Consoles, Terminals, and Shells in Jupyter

? Terminal mirrors the terminal in Linux terminals, Terminal.app (macOS), and

PowerShell (Windows)

- Runs more than just python

? Console provides IPython interface

- Easier multi-line editing

- Reference past outputs directly, other bells and whistles

? Shell will run in the Terminal app

? Can also use shell commands in the notebook using !

- !cat

- !head -n 10

D. Koop, CSCI 503, Spring 2021

3

Python and CLIs

? Python can be used as a CLI program

- Interactive mode: start the REPL

?

$ python

- Non-interactive mode:

?

$ python -c : Execute a command

?

$ python -m |: Execute a module

? Python can be used to create CLI programs

- Scripts: python my_script.py

- True command-line tools: ./command-written-in-python

D. Koop, CSCI 503, Spring 2021

4

Interactive Python in the Shell

? Starting Python from the shell

- $ python

? >>> is the Python interactive prompt

- >>> print("Hello, world")

Hello, world

- >>> print("2+3=", 2+3)

2+3= 5

? This is a REPL (Read, Evaluate, Print, Loop)

D. Koop, CSCI 503, Spring 2021

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download