[Tutor] Cannot understand object initiation

Kush Goyal kushgoyal.89 at gmail.com
Mon Oct 14 15:27:44 CEST 2013


Hi,

Thanks a lot Bob and Allan for the help.

I tried experimenting with classes and objects on python interpretor
and learned that in python functions, classes, method, objects and
modules all can be passed around and returned.

>From what I understood from your answers:

user = User.query.filter_by ( username = self.username.data ).first()

returns a reference to an instance of class User. So user is an object
of type User class.

Also, db is an sqlalchemy engine and db.Model is a class.

db.Model is I think a sqlalchemy declarative base class which has all
the needed methods and classes for database handling.

So, did I get the above things right?

Thanks!

Kush


On Sat, Oct 12, 2013 at 10:17 PM, bob gailer <bgailer at gmail.com> wrote:
> On 10/12/2013 11:01 AM, Kush Goyal wrote:
>>
>> [[snip]
>>
>> "user = User.query.filter_by ( username = self.username.data ).first()"
>>
>> now this I do not understand.
>>
>> Can a object be create by using a method of a class instead of the
>> class consturctor? I
>
> Without seeing the code you reference (User module) I can hazard a guess:
>
> This code is not creating an object - it is returning a reference to an
> existing object.
>
> The key to the object is username, and first() returns the first instance
> should there be more than one,
>
> User is some objectimported from myapplication.models.
> query is a callable object that is an attribute of User.
> filter_by is a callable object that is an attribute of query.
> first is a callable object that is an attribute of filter_by.
> Nothing in the above suggests object creation.
>
> HTH
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>


More information about the Tutor mailing list