Pluggable Apps

A Django project is made of multiple apps that can be reused and moved from project to project.When you name […]

Read More

Views

Django is an MVC, or model-view-controller framework, but Django doesn’t call templates views, it calls them templates. And it doesn’t […]

Read More

Starting With Django

Installing PIP If PIP did not come installed with Python 3, do the following: Download get-pip.py from: http://pip.readthedocs.org/en/stable/installing.html If PIP is not Python […]

Read More

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

Set Comprehension

Double Loop We create a set with curly braces, just like we do for a dictionary. But sets don’t have […]

Read More

Dictionary Comprehension

Created from Iterable {number: letter for letter, number in zip(‘abcdefghijklmnopqrstuvwxyz’, range(1, 27))} Output {1: ‘a’, 2: ‘b’, 3: ‘c’, 4: […]

Read More

List Comprehension

We call up a list comprehension not because it deals with the list but because it creates a list. Comprehensions […]

Read More

Read from Files

How to read in the contents of a file in Python. def rememberer(thing): with open(“database.txt”, “a”) as file: file.write(thing+”\n”) def […]

Read More

Writing to Files

You often need to write to a file to store data for later use. Python makes this really straightforward! To […]

Read More

Stub Files

What if you need to work with Python versions before 3.5 and you still wanna use types.Or maybe you don’t […]

Read More

Custom Types

Sometimes you can’t specify your types just with the built-in types. In that case, you can us Optional, Union, and List from the typing module to […]

Read More

Built-in Types

Python, like JavaScript and Ruby, and many other languages, is dynamically typed. This means that a variable like name could […]

Read More

Debugging in the Browser with Source Maps

With source maps (i.e. the .css.map files), we can use our browser’s developer tools to view the original Sass source, instead […]

Read More