[Tutor] need some class / module help

shawn bright nephish at gmail.com
Fri Oct 20 20:18:10 CEST 2006


oh, one more thing.
these objects are going to be created at the rate of about 20 / minute in a
thread.
at some point is this going to be a problem ? do they go away over time?
Or do i need to write something that will kill them?

thanks
sk

On 10/20/06, shawn bright <nephish at gmail.com> wrote:
>
> Hey thanks for the help,
> yes, the class in in another file called group. the class Group is the
> only class in the module. I am doing this because the script that will call
> it is not the only place in all our scripts where it can be used. I have
> been doing stuff with python for over a year now, thought i would take
> advantage of some stuff that might save me some time.
>
> thanks again
> shawn
>
> On 10/20/06, Bob Gailer <bgailer at alum.rpi.edu> wrote:
> >
> >  shawn bright wrote:
> >
> > Hey there,
> >
> > I am trying to create a module with one class
> > the module name is group.py
> >
> > it looks like this so far
> >
> > import DbConnector
> >
> > class Group(object):
> >
> >     def __init__(self, id):
> >         self.id = id
> >         con = DbConnector.DbConnector()
> >         query = con.getOne("select `name`, `position` from `groups`
> > where `id` = '"+id+"' ")
> >         self.name = query[0]
> >         self.position = query[1]
> >
> >     def set_position(position):
> >         self.position = position
> >         con.update("update `groups` set `position` = '"+self.position+"'
> > where `id` = '"+self.id"' ")
> >
> > now lets say i wanted to do
> >
> > mygroup = Group.group(12)
> > position = mygroup.position() # gives me position of group where id = 12
> > mygroup.set_position(13) # changes value of position to 13
> >
> >     Is this code in another module?
> >     If so you need:
> > import group
> >    and
> > mygroup = Group.group(12)
> >    should be (module name followed by class name)
> > mygroup = group.Group(12).
> >
> > mygroup.position() # this is a call, and position is not callable.
> >     should be
> > mygroup.position
> >
> > "select `name`, `position` from `groups` where `id` = '"+id+"' "
> >     is OK but an easier to read version is:
> > "select `name`, `position` from `groups` where `id` = '%s'" % (id,)
> >
> >
> > is this right?
> > i would test it here, but the database is not available. I am writing
> > this to implement an easier way to code something very long later.
> >
> > Just wanted to know if i am on the right track.
> >
> > if you have read this far, thanks !
> >
> > sk
> >
> >
> >
> >
> >
> > ------------------------------
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.orghttp://mail.python.org/mailman/listinfo/tutor
> >
> >
> >
> > --
> > Bob Gailer
> > 510-978-4454
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061020/5a9d0ec3/attachment.html 


More information about the Tutor mailing list