Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91179 > unrolled thread

Re: Camelot a good tool for me

Started byLele Gaifax <lele@metapensiero.it>
First post2015-05-24 15:28 +0200
Last post2015-05-24 15:28 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Camelot a good tool for me Lele Gaifax <lele@metapensiero.it> - 2015-05-24 15:28 +0200

#91179 — Re: Camelot a good tool for me

FromLele Gaifax <lele@metapensiero.it>
Date2015-05-24 15:28 +0200
SubjectRe: Camelot a good tool for me
Message-ID<mailman.17.1432474106.5151.python-list@python.org>
Chris Angelico <rosuav@gmail.com> writes:

> You don't automatically get nice objects with attributes named after
> columns, but neither will SQLAlchemy unless you're doing the
> equivalent of "select * from". Example:
>
>>>> session.query(Student).all()
> [<__main__.Student object at 0x7fc2de3fc290>, <__main__.Student object
> at 0x7fc2de3fc350>, <__main__.Student object at 0x7fc2de3fc3d0>]
>
> That's a list of Student objects, because I asked for the entire table.
>
>>>> session.query(Student.name, Student.year).all()
> [(u'Fred', 2015), (u'Joe', 2015), (u"Robert'); DROP TABLE Students;--", 2012)]
>
> That's a list of tuples, because I asked for just two columns.

Wrong:

    >>> res = session.query(Student.name, Student.year).all()
    >>> type(res)
    <class 'list'>
    >>> type(res[0])
    <class 'sqlalchemy.util._collections.result'>
    >>> type(res[0].name)
    <class 'str'>
    >>> type(res[0][0])
    <class 'str'>
    >>> res[0].name == res[0][0]
    True

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web