# Cart.py # Modules and Libraries page 34 ''' FileName Cart.py Module/Library Name (filename without the extension) Cart Default Class (filename without the extension) Cart Default Constructor (ClassName with a tuple decorator) Cart() Default Finalizer ~ClassName ~Cart Default attribute for __name__ is __ClassName__ with 2 underscores at each end __Cart__ ''' ''' def myCalc() default __name__ myCalc default constructor myCalc() ''' ''' Types of Modules and Libraries Python Core <3> Core set of functions your get when you install Python There is NO need to use the import keyword print() int() str() input() tuple() list() format() if else for in keywords Python Standard <version> Versions have a 5 year lifecycle Versions are version specific - Don't just update codes versioning You will get various modules and libraries with your version. BUT you must import these manually. Methods to import for Standard AND Custom Modules import ModuleName <Module/Library> Name is the filename without the extension Cart.py -> ModuleName Cart -> import Cart Customer.ipynb -> ModuleName Customer -> import Customer .pyc, .pyo, .pyi, .pyd, ... import ModuleName as Namespace/Alias import Cart as myCart -> I would call objects using myCart, you can not call the objects with Cart <__name__> to the namespace from ModuleName/LibraryName import ObjectName from Cart import taxCalc taxCalc object may be a function/method taxCalc(), but you only use the __name__ for the import ObjName Custom Modules and Libraries All other python files, either that you create, a third party creates or you get from the pypi.org python repository LBYL Principle -> Look Before You Leap Normally not version specific related to Core.Version ''' # Shopping Cart Objects def cartSubTotal(): # simulate the session data as float var_sessionTotal = 100.00 # local var in scope = AmountInTheCart rtn_cartSubTotal = var_sessionTotal # return var = local variable return rtn_cartSubTotal # return to the class # return rtn_cartSubTotal = var_sessionTotal = 100.00 def taxRate(param_cartSubTotal, param_TaxPerc): # taxRate(100,7) ''' This function will expect 2 parameters. One for the cart subtotal and one for the tax percentage. The cart subtotal will come from the session data and the tax percentage will come from the tax table in the database. ''' # Method 1 -> assign the passed param to a local variable var_TaxPerc = param_TaxPerc # 7 = 7 # use the local variables in the scope of the function var_TaxRate = var_TaxPerc / 100 # 7 / 100 = .07 varAmountOfTax = param_cartSubTotal * var_TaxRate # 100 * .07 $7.00 rtn_AmountOfTax = varAmountOfTax return rtn_AmountOfTax ''' # Method 2 -> just use the passed param in the scope of the function param_cartSubTotal * var_TaxRate ''' def cartTotal(): pass def shipppingCost(): pass def customerInfo(): pass def ccInfo(): pass