Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'attributes': 0.07; 'objects,': 0.07; 'table.': 0.07; 'received:151': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'res': 0.09; 'example:': 0.11; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sqlalchemy': 0.16; '>>>': 0.20; 'student': 0.20; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'chris': 0.26; 'equivalent': 0.27; 'asked': 0.28; 'objects': 0.29; 'table': 0.32; 'drop': 0.35; 'to:addr:python-list': 0.35; 'list': 0.35; 'but': 0.36; 'two': 0.37; 'subject:: ': 0.37; 'received:org': 0.38; 'doing': 0.38; 'to:addr:python.org': 0.39; 'entire': 0.61; 'che': 0.63; 'quello': 0.84; 'subject:good': 0.84; 'subject:tool': 0.84; 'quando': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Lele Gaifax Subject: Re: Camelot a good tool for me Date: Sun, 24 May 2015 15:28:07 +0200 Organization: Nautilus Entertainments References: <87fv6ol93p.fsf@nautilus.nautilus> <20150522224229.GA62222@cskk.homeip.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 151.62.69.113 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5.50 (gnu/linux) Cancel-Lock: sha1:C3u9nYv6Q/YGNEHxRU555a0Fizs= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432474106 news.xs4all.nl 2953 [2001:888:2000:d::a6]:52587 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91179 Chris Angelico 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) >>> type(res[0]) >>> type(res[0].name) >>> type(res[0][0]) >>> 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.