Struct usages in Python

Patrick Mullen saluk64007 at gmail.com
Wed May 28 01:07:10 EDT 2008


I don't know if this will go through (my posts seem to have become blocked
lately), but I'll give it a shot anyhow.

You seem to be under a misconception that a python list is similar to a list
in say, Java or other languages that have a rigid idea of variables and
types.  In python, a list is a list of objects - any type of object can be
stored in a list.  Just as you don't declare types for variables, you also
don't declare types for lists.  Here is your modified code:

class Event():
   def __init__(self, cameraEventType="", zone=99, setDay="",setTime ="",
clrTime=""):
     self.cameraEventType = cameraEventType
     self.zone = zone
     self.setDay = setDay
     self.setTime = setTime
     self.clrTime = clrTime

class EventTimeFilter:
   def __init__(self):
           self.event = []  #Create an empty list, bind to the name "event"
under the "self" namespace
           self.event.append(Event())   #Create an event object and append
to the end of the list


Python won't stop you from putting other objects into self.event besides
Event objects, but in practice this isn't often an issue.  The real benefit,
is if you subclass event or make some other type of object that is similar
to events, with maybe some of the same fields, you can still store them in
the list and it will play along with the rest of your code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080527/ba8cbdbe/attachment.html>


More information about the Python-list mailing list