This module covers Python tools and techniques for engineering applications. Topics progress from advanced data structures and functions through practical file processing, text parsing, and command-line scripting.
liststuplesdictionaries.py
Comprehensive coverage of Python's core data structures:
- Lists: creation, operations, slicing, iteration
- Tuples: immutable sequences, unpacking, use as dictionary keys
- Dictionaries: key-value pairs, methods, nested structures
- Practical examples: shopping carts, student grades, word frequency counting
recursion.py
Demonstrates recursive function design:
- Naive and optimized (tail-recursive) implementations
- Fibonacci sequence calculation
- Array searching with recursion
- Understanding base cases and recursive calls
advancedfunctions.py
Function parameter techniques:
- Positional-only parameters (/)
- Keyword arguments with defaults
- Variable-length argument lists (*args)
- Keyword-only parameters (*)
- Practical examples with statistical functions
comprehensionsintro.py
VIDEO (8:56): Concise syntax for creating collections:
- List comprehensions for transforming sequences
- Set comprehensions for unique elements
- Dictionary comprehensions for key-value pairs
- Filtering with conditional expressions
- Nested comprehensions for complex operations
strings_advanced.py
Essential string methods for engineering scripts:
- String methods: strip(), upper(), lower(), replace()
- Checking content: startswith(), endswith(), isdigit()
- Splitting and joining: split(), join()
- String formatting: f-strings, .format(), alignment
- Extracting data from structured text
- Finding and locating substrings
regex.py
Pattern matching and text extraction:
- Basic pattern matching with re.search()
- Extracting numbers and codes from text
- Email validation patterns
- Finding all matches with re.findall()
- Replacing with patterns using re.sub()
- Splitting text on patterns
- Pattern syntax: \d, \w, [a-z], +, *, ?, {n,m}
csv_files.py
Reading and writing comma-separated data:
- Reading CSV with csv.reader()
- Dictionary access with csv.DictReader()
- Filtering and extracting specific columns
- Writing CSV files with csv.DictWriter()
- Handling different delimiters (semicolon, tab)
- Aggregating and summarizing CSV data
fileio_engineering.py
File operations for engineering workflows:
- Writing files with open() and write()
- Reading entire files and line-by-line processing
- Appending to existing files
- Filtering file contents
- Processing structured data from files
- Working with file metadata and directories
error_handling.py
Writing robust scripts with exception handling:
- try/except for handling specific exceptions
- ValueError, FileNotFoundError, TypeError
- Multiple exception types in one script
- Else and finally clauses
- Raising custom exceptions
- Exception chaining with "from"
- Handling bad data in loops gracefully
commandline_engineering.py
Making scripts flexible with arguments:
- Accessing command-line arguments (sys.argv)
- Processing required and optional arguments
- Common patterns for argument handling
- Usage messages and error checking
- Examples: file analyzer, unit converter
- Introduction to argparse for complex scripts
| Topic | File | Key Concepts |
|---|---|---|
| Data Structures | liststuplesdictionaries.py | Lists, tuples, dicts, operations, unpacking |
| Recursion | recursion.py | Base cases, recursive calls, optimization |
| Advanced Functions | advancedfunctions.py | *args, keyword args, default values |
| Comprehensions | comprehensionsintro.py | List, set, dict comprehensions, filtering |
| String Methods | strings_advanced.py | strip, split, replace, find, format |
| Regular Expressions | regex.py | Pattern matching, extraction, validation |
| CSV Files | csv_files.py | Reading, writing, filtering, aggregation |
| File I/O | fileio_engineering.py | Reading, writing, appending, processing |
| Error Handling | error_handling.py | try/except, exception types, robustness |
| Command-Line Args | commandline_engineering.py | sys.argv, argument processing, usage |
Each file can be run directly:
python liststuplesdictionaries.py
python recursion.py
python advancedfunctions.py
python comprehensionsintro.py
python strings_advanced.py
python regex.py
python csv_files.py
python fileio_engineering.py
python error_handling.py
python commandline_engineering.pySome examples create temporary files during execution and clean them up automatically.
- Read the file (fileio_engineering.py)
- Parse each line (strings_advanced.py)
- Handle errors gracefully (error_handling.py)
- Aggregate results (liststuplesdictionaries.py)
- Use regex patterns (regex.py)
- Process with comprehensions (comprehensionsintro.py)
- Store in dictionaries (liststuplesdictionaries.py)
- Write results to CSV (csv_files.py)
- Accept arguments (commandline_engineering.py)
- Validate input (error_handling.py)
- Process files (fileio_engineering.py)
- Handle exceptions gracefully (error_handling.py)