On Sun, Apr 11, 2010 at 11:57:18PM +0930, ross kyprianou wrote: > Learned a little about the Categories setup > Next step is to override the __repr__ method > > Is the "B[word: ....]" string formed in a __str__ or __repr__ method? > If so, Im trying to work out where it is (so I can base the new code on it) > > I ran these... > > sage: C = AlgebrasWithBasis(QQ) > sage: A = C.example(('p','q','r')) > sage: (P,Q,R) = A.algebra_generators() > sage: P.__repr__() > > 'B[word: p]' > > sage: P.__repr__?? # showed me code from > devel/sage/sage/structure/sage_object.pyx
Yup. That's actually a general Sage setup, independent of categories; SageObject specifies that "repr" should be implemented as _repr_ (SageObject.__repr__'s job being to allow for the rename feature). If you try P._repr_? instead, you will see that it is implemented in CombinatorialFreeModule (please ignore the "Combinatorial" in the name; it is just an accident in history that will disappear at some point). Note that it is not in the ModulesWithBasis category, though it probably should, since it is not that much tied to the data structure. You will see also that you can play with A._repr_term and A.prefix for customizing the default _repr_ for elements. Oh, and a tip for such situations: sage: for c in A.__class__.mro(): print c <class 'sage.categories.examples.algebras_with_basis.FreeAlgebra_with_category'> <class 'sage.categories.examples.algebras_with_basis.FreeAlgebra'> <class 'sage.combinat.free_module.CombinatorialFreeModule'> ... Best, Nicolas -- Nicolas M. ThiƩry "Isil" <nthi...@users.sf.net> http://Nicolas.Thiery.name/ -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org To unsubscribe, reply using "remove me" as the subject.