i come matlab background. in matlab can create class definition , create array of objects. can dereference each object index. in addition, when call method object array (without index), have access objects in array. e.g, mynewclass has properties .data , .text, has method .clob. can:
% init a(1) = mynewclass; a(2) = mynewclass; a(1).data = [0;0;0]; a(2).data = [1;1;1]; so now, if call a.clob (not a(1).clob or a(2).clob), can like
% function inside methods definition of class definition function clob(self) % self here object array, "a", above i=1:length(self) % deref single object self(i).goclobyourself; end end how do in python? please note, want class indexed collection, kind of list. but, don't want "class-list" accept class, mynewclass. if inherit "list," class "list" class attributes .data, .text, , function .clob? note, don't want "list" contains objects, want objects list can deref them index: a[1].clob() or a(1).clob() (?? or that). or, want pass whole array self: a.clob() gives me access list. may have terminology little cloudy.
best regards
all such capabilities in python use "special method names" described in language reference section 3.3. section 3.3.6 describes how emulate container types, in general you're asking here. need define , implement methods __getitem__, __setitem__,__delitem__ , perhaps __iter__, __reversed__ , __contains__. python quite , approach flexible.
Comments
Post a Comment