XPYM300111 InstructorPhilipM-1 Philip Matusiak philipm@onlc.com 10 E - 1 E 1 E - 1:45 E Lunch 1:45 E - 4:45 E def myCalc(): x = 7 y = 3 z = x + y print(z) return "themselves" function # 10 call myCalc() print(myCalc()) Method > function that returns somewhere else "Class" public myCalc() { } super() Core Standard Custom Python Pythonic Application Factory > Container / Token PROVIDER > INPUTS / APIS / IO Service > Web Service / apis / injectables "namespace" Modules > Collections defaultdict LL dict type HL Class > wrapper for objects Contacts Object method() return Contacts.Contact convert.ToInt() Property (type and var name) implicitly Contacts.Contact.fname value "Philip" string fname casting > view My name is Philip open("contacts.csv"): .reader() file = "contacts.csv" open(filename): with open(file) as file: file.reader() import MODULENAME import datetime from MODULE import Class from datetime import date import MODULENAME as ns import datetime as dt class Contacts: def openContacts: with open(filename) as file: file.reader() openContacts() compiler (php,cf,asp) > html memory/proc intensive engine (java's) > encapsulation { } memory intensive less proc framework (C#, VB.net, asp.net, angular, react,...) interperter (python) signlanguage "Philip" 'P' 'h' 'i' list [] single, dups, indexed,mut len3 range0-2 set {} single, !dups, !indexed, !sort, mut {"Bob","Joe","Bob"} len2 {"Bob","Joe"} {"Joe", "Bob"} tuple () single, dups, indexed, immut dictionary dict {} key:value key!dup , valuedup, mut Someone help you out > control, customization, optimization HL dict type Collections Class { "fname": "Bob" } Dict Class { "fname": "Bob" } break 11:30 E - 11:45 E class code lab philipm@onlc.com Philip Matusiak AFK... VS Code Test python folder for class / save ws / chapter5.py property > fname = "Philip" data type string "" char '' bool True/False int 21 variable name fname value Philip string age; age = "21" age.ToInt() conversion int(age) casting fname = "Bob" > assert Bob property of an Object _fname = "Bob" > assert Bob hidden property of an Object __fname__ = "Bob"> getter Bob Property of a Class underscore_case snake_case camelCase TitleCase lowercase UPPERCASE Contact.fname Contact._fname class Contact: __init__ fname __fname__ value Bob A.F.P.S.C.O.m.p.value A.C.C.O A.F.C.p.O.p.C.S.m.p.value MVC Class > Properties Behaviors def __something__(): BEFORE blueprint Properties/Behaviors ops def something(): AFTER inside class instances ops class Contacts: def __init__() google.com domain.root self. self param defines instance of a class this. string fname; constructor(firstname) { this.fname = firstname } Contact("Bob","Smith") self1 > self this1 > this onlclabs.com lunch 1:25 E - 2:10 E philipm@onlc.com 800.288.8221 connected both sessions and audio static instance abstract myContact = new Contact() myContact = Contact.create() Product 3 params name,sku,price DetailedProduct 2 params description, size tblProducts has 57 fields, cd, md, user Product only 3 params list of products onClick() super details more fields < subclass class DetProd(Product): join + "Product Name " + productName params "Product Name", productName template f"Product Name {productName}" ToString() "Product Name {} Sku {}".format(productName, sku) verbose @"Product Name {productName}" orderID, orderDate high level modules "review" pypdf.copy() low level modules "granular / flexible" IO.copy() txt, import csv os (Windows / Linux / Mac / ...) sys interpreter break 3:45 E - 4:00 E class Orders chapter6.py Orders datetime now() subprocess > create log orderID, orderDate user input qty int(input()) 2 processes 1. output to term 2. log file if else > input() property try except finally throws TYPE ERROR class regex ^[1-9][0-9][0-9] if (input > 0) micro > api > Day 2 debug the process script error copy up chapter6.py then chapter 7 -Value '{log_message}'" -Value \"{log_message}\"" f'string stuff " " ' onlclabs.com/python ccInfo = ('4111 2541 5412 5214', '12/25', '412') break 11:35 E - 11:50 E loops / interators 1. control __init__ 2. condition __next__ 3. return __iter__ Data Architecture > Class Class Objects var Storage Container Objects Data Stream Objects > yield / Obs & Prom / Sub & Beh iterate() enumerate() Generators > data streams > infinate seqs "^[a-zA-Z0-9_.]+@[a-zA-Z0-9]+?\.[a-zA-Z]{2,3}$" Python > use the if keyword to test the regex value to return Pythonic > use bool(test value) return lunch 12:55 E - 1:40 E code our import re Standard chapter 8 DRY principle of OOP keyword, op, code, DM view template if elif elif else property var data type switch case case default Object function( function()) bool() Class try finally Service Class() Class() PROVIDER S S Factory P P 3 Base Levels Debugging Syntax > correct typing code IDE Runtime > at runtime code __init__ Class P and B Exception > throws or raises try except finally Front End > UI/UX View > Controller Class View stable 1. __init__ 2. view unstable Exit 0 a. call service/PROVIDER/Factory b. UI/UX functionality c. timer (wait, timer) MVC DM 0 C 0 V unstable > Controller Class View stable APP Exit Code 1 Backend Testing UnitTesting Assert x + y 100 + 7% x * y 100 * .07 Class Testing test functions in the class Unit Test > unittest Module Standard (xUnit, fixtures, suites) Class Testing > pytest (simple, customize failures > log file) Suite APP > P Class 1 > P @funct1_1() > P @funct1_2() > P Class 2 > P @funct2_1() > P funct2_2( > tax_calc() cart_total = 107.00 Assertion function2_2a() > sub_total + perc F 100 + .07 ) @funct2_3() > P pytest pip install module_name easier syntax > testing self.Assert() parameter testing extend testing plugins pytest Class(InjectingClass) Class.Class break 3:15 E - 3:30 E pytest pytest You do not need a class wrapper pytest command line utility pytest pip install pytest test_ pytest chapter8Pytest.py # pip install pytest-mock Next Steps > Python Level 3 Data Analysis, Audit Program, Book, Download onlclabs.com/python Certificate of Completion philipm@onlc.com Digital Access Key onlc.com/eval