from sqlalchemy import create_engine
from sqlalchemy import Sequence
Base = declarative_base()
Column(Integer, Sequence('user_id_seq'), primary_key=True)
engine = create_engine('sqlite:///:memory:', echo=True)
class User(Base):
__tablename__ = 'users'
id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
name = Column(String(50))
fullname = Column(String(50))
nickname = Column(String(50))
def __repr__(self):
return "<User(name='%s', fullname='%s', nickname='%s')>" % (
self.name, self.fullname, self.nickname)
class User1(Base):
__tablename__ = 'users1'
id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
name = Column(String(50))
fullname = Column(String(50))
nickname = Column(String(50))
def __init__(self, name, fullname, nickname):
self.name = name
self.fullname = fullname
self.nickname = nickname
def __repr__(self):
return "<User(name='%s', fullname='%s', nickname='%s')>" % (
self.name, self.fullname, self.nickname)
ed_user = User(name='ed', fullname='Ed Jones', nickname='edsnickname')
ed_user = User1(name='edd', fullname='Edd Jones', nickname='edsnick')
i picked up this piece of code from the sqlalchemy documentation website, I think everything is okay, but i have a problem understanding the last line, the class user inherits from the base class, buy the user class is not having an init methods in other to accept any argument. can some please explain this to me.. thanks. this two-class achieves the same result they create a table, but in the second instance, the User1 has an init method declared, so obviously the creation of the table happens in the base class, but in the second instance the class and instance variable were declared I want to know how will the base class be able to create the table if it is not receiving any data from the child class.