Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 1.18 KB

File metadata and controls

50 lines (34 loc) · 1.18 KB

PYTHON Python::snippets

Main program structure

link:snippets.py[role=include]

see code at snippets.py

Find first element in a sequence that matches a predicate

 — from: stackoverflow

finding first
next((x for x in range(10) if x > 3), 'not found')
# will return 4

will return the first number from 0 to 10 above 3, ie 4.

not finding
next((x for x in range(10) if x > 10), 'not found')
# will return 'not found'

there is no number above 10 in range(10), returns "not found" in that case.

List files

see path

check a variable exists

local

global

attribute of an object

'myVar' in locals()

'myVar' in globals()

hasattr(obj, 'attr_name')

web server

python -m http.server 8000