dice.py

For Python Testing lessons. import random import re die_pattern = re.compile(r’^(?P<num>\d+)d(?P<sides>\d+) , re.I) class Die: value = None def __init__(self, […]

Read More

Exercises

Exercise: Subclassing int Alright, time to subclass int.Make a class named Double that extends int. Now override new. Create a new int […]

Read More

Method Protection

There is no foolproof way of protecting your code from outside use in Python.But if you follow the conventions in […]

Read More

Classmethods

Constructions What if we need something more complex than just a custom init or new method? Constructors, as most classmethods […]

Read More

Subclassing Built-ins: List & Dict

Subclassing List Build a list that can be prefilled with a certain number of numbers. filledlist.py Testing _This underscore ignores […]

Read More

Subclassing Built-ins: Strings

Subclassing String We used init when we wanted to customize how a new instance of a class is created. new works very similarly. The […]

Read More

Iterable Object

__len__Gives your object a collection length. __contains__For checking membership (e.g. using in). __iter__Makes your object iterable. yield lets you send data back […]

Read More

Magic Methods

What if our instances should be able to be used with mathematical operations? We can define that! __init__In this program, […]

Read More

My Python Notes

  A list must be homogeneous, its elements all should be from the same type. If an element in a […]

Read More

Class Family Tree

Being able to identify object classes and types is a really useful ability. isinstance(<object>, <class>) Tells you whether or not […]

Read More

Multiple Inheritance

We now have changed and updated the design of our app. Character Agile Sneaky |_______________|______| | Thief Tightly/Loosely Coupled Design […]

Read More

Inheritance and __init__

__init__ of class def __init__(self, name, sneaky=True, **kwargs): self.name = name self.sneaky = sneaky for key, value in kwargs.item(): setatter(self, […]

Read More

OOP Explained

Objects are nouns that can be described with adjectives (attributes) and can do things with verbs (methods). Classes are the […]

Read More

Set Functions & Operands

Let’s pretend we have two sets. The first set will be the first ten positive whole numbers. The second will […]

Read More

Set Basics

Set Characteristics Unique A set is a collection of unique items that belong together for some reason. Example: A set […]

Read More

Python Review

##################################################### ###################### General ###################### ##################################################### print(“Bashar”) help(print)       # Helps you understand what the function print() does help(str.rjust)   # Helps you […]

Read More

More Commands

Creating a simple local server using Python3 python3 -m http.server

Read More
Comments Off on More Commands

Diary Functions

[diary.py] #!/user/bin/env python3 import datetime import sys import os from collections import OrderedDict from peewee import * db = SqliteDatabase(‘diary.db’) […]

Read More
Comments Off on Diary Functions

Creating a Diary

[diary.py] #!/user/bin/env python3 from collections import OrderedDict import datetime from peewee import * db = SqliteDatabase(‘diary.db’) class Entry(Model): content = […]

Read More
Comments Off on Creating a Diary

C.R.U.D.

Create, Read, Update, Delete .select()  Displays records .create    Creates a new record .save()    Updates an existing record in the […]

Read More
Comments Off on C.R.U.D.