<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
shawn bright wrote:
<blockquote
 cite="mid384c93600610200921p4a3d3b50vd18b84871ca52e9c@mail.gmail.com"
 type="cite">Hey there,<br>
  <br>
I am trying to create a module with one class<br>
the module name is group.py<br>
  <br>
it looks like this so far<br>
  <br>
import DbConnector<br>
  <br>
class Group(object):<br>
  <br>
&nbsp;&nbsp;&nbsp; def __init__(self, id):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://self.id">self.id</a> = id<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con = DbConnector.DbConnector()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; query = con.getOne("select `name`, `position` from `groups`
where `id` = '"+id+"' ")<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://self.name">
self.name</a> = query[0]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.position = query[1]<br>
  <br>
&nbsp;&nbsp;&nbsp; def set_position(position):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.position = position<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.update("update `groups` set `position` =
'"+self.position+"' where `id` = '"+self.id"' ")
  <br>
  <br>
now lets say i wanted to do <br>
</blockquote>
<blockquote
 cite="mid384c93600610200921p4a3d3b50vd18b84871ca52e9c@mail.gmail.com"
 type="cite">mygroup = Group.group(12)<br>
position = mygroup.position() # gives me position of group where id = 12<br>
mygroup.set_position(13) # changes value of position to 13<br>
</blockquote>
&nbsp;&nbsp;&nbsp; Is this code in another module? <br>
&nbsp;&nbsp;&nbsp; If so you need:<br>
import group<br>
&nbsp;&nbsp; and <br>
mygroup = Group.group(12) <br>
&nbsp;&nbsp; should be (module name followed by class name)<br>
mygroup = group.Group(12).<br>
<br>
mygroup.position() # this is a call, and position is not callable.<br>
&nbsp;&nbsp;&nbsp; should be <br>
mygroup.position<br>
<br>
"select `name`, `position` from `groups` where `id` = '"+id+"' "<br>
&nbsp;&nbsp;&nbsp; is OK but an easier to read version is:<br>
"select `name`, `position` from `groups` where `id` = '%s'" % (id,)
<blockquote
 cite="mid384c93600610200921p4a3d3b50vd18b84871ca52e9c@mail.gmail.com"
 type="cite"><br>
is this right?
  <br>
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.<br>
  <br>
Just wanted to know if i am on the right track.<br>
  <br>
if you have read this far, thanks !
  <br>
  <br>
sk<br>
  <br>
  <br>
  <br>
  <br>
  <br>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Tutor maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:Tutor@python.org">Tutor@python.org</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a>
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
Bob Gailer
510-978-4454</pre>
</body>
</html>