[Tutor] problem importing class
Kent Johnson
kent37 at tds.net
Thu Oct 26 18:33:17 CEST 2006
shawn bright wrote:
> hey there
>
> i have written a module called site.py
Use a different name, there is a library module called site that is
automatically imported when Python starts up. So when you 'import site'
you are getting the already-imported library module.
Kent
> in the file i have this:
>
> import DbConnector
> import sensor
>
> class Site(object):
> "site object"
>
> def __init__(self, id):
> self.id <http://self.id> = id
> self.con = DbConnector.DbConnector()
> id = str(self.id <http://self.id>)
> stats = self.con.getOne("selct `group_id`, `name`, `ivr_code`, \
> `site_type`, `notes`, `sensor_id` \
> from `sites` where `id` = '"+str(id)+"' ")
> self.group_id = stats[0]
> self.name <http://self.name> = stats[1]
> self.ivr_code = stats[2]
> self.site_type = stats[3]
> self.notes = stats[4]
> self.sensor_id = stats[5]
>
> def get_sensor(self):
> self.sensor = sensor.Sensor (self.sensor_id)
> return self.sensor
>
> ok, in the program i am trying to run i have these lines:
> import site
> new_site = site.Site(id_number)
>
> and this is what my output is:
> Traceback (most recent call last):
> File "./new_camp.py", line 2014, in on_site_tree_view_row_activated
> acitve_site = site.Site(id_number)
> AttributeError: 'module' object has no attribute 'Site'
>
> It looks like the same code works for a different module i have ;
> i don't get what i could be missing here, any tips?
>
> if you have read this far, thanks for your time.
> sk
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list