On Thu, Apr 26, 2018 at 11:30:13PM -0700, Jose Miguel Ibáñez wrote: > Please, find below an example of what I mean: > > class User(Base): > id = Column(Integer, primary_key=True) > name = Column(String) > fullname = Column(String) > > def __init__(self, name, fullname): > > self.name = name > self.fullname = fullname > > > is the __init__() method recommended ?
The __init__() method is optional when you use Declarative, as the Declarative extension provides a default constructor which accepts keyword names that match the mapped columns (Of course you are free to define any explicit __init__ to override the default one) > > > El jueves, 26 de abril de 2018, 18:48:53 (UTC+2), Jose Miguel Ibáñez > escribió: > > > > Hi all ! > > > > when defining a class (derived from Base), when is recommended to define > > the __init__() method ? I know this consideration https://goo.gl/2umBJv, > > but I can't see the diference when creating objects for database > > population. It seems __init_() is never required. > > > > Thanks ! > > José M. > > > > > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- Julien Cigar Belgian Biodiversity Platform (http://www.biodiversity.be) PGP fingerprint: EEF9 F697 4B68 D275 7B11 6A25 B2BB 3710 A204 23C0 No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: PGP signature