0

I'm reading Essential SQLALchemy 2nd.

Following code was copied from this book

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, Integer, Numeric, String, Boolean

Base = declarative_base()

class Cookie(Base):
    __tablename__ = 'cookies'

    cookie_id = Column(Integer(), primary_key=True)
    cookie_name = Column(String(50), index=True)
    cookie_recipe_url = Column(String(255))
    cookie_sku = Column(String(55))
    quantity = Column(Integer())
    unit_cost = Column(Numeric(12, 2))

Cookie.__table__

The result in book is

Table('cookies', MetaData(bind=None), Column('cookie_id', Integer(), table=, primary_key=True, nullable=False), Column('cookie_name', String(length=50), table=), Column('cookie_recipe_url', String(length=255), table=), Column('cookie_sku', String(length=55), table=), Column('quantity', Integer(), table=), Column('unit_cost', Numeric(precision=12, scale=2), table=), schema=None)

But in my environment it just show the table name my resut1 I'm using Python 3.6 sqlalchemy 1.2

Haseo
  • 23
  • 5
  • To open up the dupe a bit: `Table('cookies', MetaData(...), ...)` is the [`repr()`](https://docs.python.org/3/library/functions.html#repr) representation of a `Table` instance. [`print()`](https://docs.python.org/3/library/functions.html#print) on the other hand converts all non-keyword arguments to string in the same fashion as [`str()`](https://docs.python.org/3/library/stdtypes.html#str) does. – Ilja Everilä Feb 07 '18 at 09:30
  • Thanks a lot ;) – Haseo Feb 08 '18 at 05:56

0 Answers0