O'Reilly logo

Python 3 Web Development Beginner's Guide by Michel Anders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action using the Entity class

Let us first define for ourselves how we want to use an Entity class, because the interface we create must match as closely as possible the things we would like to express in our code. The following example shows what we have in mind (available as carexample.py):

Chapter5/carexample.py

from entity import Entity
class Car(Entity): pass
Car.threadinit('c:/tmp/cardatabase.db')
Car.inittable(make="",model="",licenseplate="unique")
mycar = Car(make="Volvo",model="C30",licenseplate="12-abc-3")
yourcar = Car(make="Renault",model="Twingo",licenseplate="ab-cd-12")
allcars = Car.list()
for id in allcars:
	car=Car(id=id)
	print(car.make, car.model, car.licenseplate)

The idea is to create a Car class that is a subclass ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required