Storing records from a parsed file

Ben Benjamin.Barker at gmail.com
Sat Sep 30 16:21:15 CEST 2006


Ah I see. So istead of creating the classes diectly I use a facroty
class as a buffer - I tell it what I want and it makes the appropriate
instances. I am not enitely sure that applies here though (I may be
wrong)

Currently I have:

camera_list[]

class camera:
     def __init__(self,alpha,beta,gamma...):
         self.alpha=alpha
         self.beta=beta
         self.gamma=gamma
         ...

for (some conditions)
	camera_list.append(camera(alpha,beta,gamma...)

the append command creates an instance of the camera class and shoves
it at the end of a list for each itteration of the loop.

However, I want to recover various types of information from the text
file I am parsing - not just (as in the example above) camera data.
However I am trying to keep the interface the same.

so I can have collectSomeData.getData() as well as
collectSomeOtherData.getData()

In each case the getData impementation will be different to suit the
required task.

So something like:

class camera:
     def __init__(self,alpha,beta,gamma...):
         self.alpha=alpha
         self.beta=beta
         self.gamma=gamma
         ...

class list_type1
	def createList() :
		for (some conditions)
			camera_list.append(camera(alpha,beta,gamma...)

class list_type2
	def createList() :
		for (some other conditions)
			camera_list.append(camera(alpha,beta,gamma...)



data1=list_type1()
data2=list_type2()


data1.createList()
data2.createList()

The only change above is that I have taken the list appending loop and
put it into a class of its own.

However, wheras when the method list_type_2 was not in a class tings
worked fine, when put into a class as above and the method attempts to
create an instance of the camera class to append to its list it
complains.

I'm pretty sure there is a solution, and I think I will kick myself
when I work it out (or have it pointed out)!

Cheers,

Ben




More information about the Python-list mailing list