dice.py
Apr 05 2019- POSTED BY projecth
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 MoreThere is no foolproof way of protecting your code from outside use in Python.But if you follow the conventions in […]
Read MoreConstructions What if we need something more complex than just a custom init or new method? Constructors, as most classmethods […]
Read MoreSubclassing List Build a list that can be prefilled with a certain number of numbers. filledlist.py Testing _This underscore ignores […]
Read MoreSubclassing 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__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 MoreWhat if our instances should be able to be used with mathematical operations? We can define that! __init__In this program, […]
Read MoreA list must be homogeneous, its elements all should be from the same type. If an element in a […]
Read MoreBeing able to identify object classes and types is a really useful ability. isinstance(<object>, <class>) Tells you whether or not […]
Read MoreWe now have changed and updated the design of our app. Character Agile Sneaky |_______________|______| | Thief Tightly/Loosely Coupled Design […]
Read More__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 MoreObjects are nouns that can be described with adjectives (attributes) and can do things with verbs (methods). Classes are the […]
Read MoreLet’s pretend we have two sets. The first set will be the first ten positive whole numbers. The second will […]
Read MoreSet Characteristics Unique A set is a collection of unique items that belong together for some reason. Example: A set […]
Read More##################################################### ###################### General ###################### ##################################################### print(“Bashar”) help(print) # Helps you understand what the function print() does help(str.rjust) # Helps you […]
Read MoreCreating a simple local server using Python3 python3 -m http.server
Read More[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[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