while 1:
                tracking.update()
	        for obj in tracking.objects():
		      allobjs=[]
		      allobjs.append(obj.xpos)
		      allobjs.append(obj.ypos)
		      allobjs.append(obj.xmot)
		      allobjs.append(obj.ymot)
		      allobjs.append(obj.sessionid)
                      aobjlist.append(allobjs)

In the above snippet of code tracking.objects() returns a list of objects with above mentioned properties.
tracking.update() continuously updates obj attributes and adds new objects.

Our requirement was to have an Multi dimensional list in which objects with its values should be stored as individual list.

But the out put got is , where each xpos, ypos, xmot etc are created as individual lists for different objects.
How can this be reversed.

Recommended Answers

All 2 Replies

tracking.objects() returns a list of objects

If it does return a list then you would use
allobjs.append(obj[0])
allobjs.append(obj[1])
or allobjs.append(tacking.objects[0])
etc. We here have no way of knowing what obj[0] contains. A little more info is necessary as you seem to be using a list of classes but that is just a guess.

Ok. I understand what you are trying to tell me. But the problem is the list is dynamically updated . I don't have the number of objects that are there in the list. The list is dynamically updated once tracking.update is called. And yes the objects are classes and it is a list of classes .

allobjs.append(obj[0]).. can this format be used ? Given that obj is just a local variable used for indexing in the for loop. Well i did try a format similar to what you have put up . Since the list of objects returned will be NULL initially before any object is tracked , using indexing gives me the IndexError.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.