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 - [email protected]
http://mail.python.org/mailman/listinfo/tutor
--
Bob Gailer
510-978-4454
|
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor