Hi Christoph, On Mon, Jan 10, 2011 at 11:04:50PM +0100, Christoph Holtermann wrote: > My interest in gnucash is to have a python-shell-environment which lets me > easily access and display data. I have written some things for myself like > simple functions PrintTransaction(Transaction) and so for other objects.
You should generally avoid CamelCase for function and instance names in Python code. CamelCase should be used for class names. PEP 8 is a good style reference: http://www.python.org/dev/peps/pep-0008/ > I use IPython for that purpose. I would like to submit my tries in that > direction but for myself I would like to find the best solution for at least > these printing functions before I do to not submit something too preliminary. > > I wonder in which way a function that prints an complex object should be done. > > When looking around in the internet i saw things like object.prettyPrint(). I > came across object.__format__(). You most likely want to use __str__ and/or __unicode__. http://docs.python.org/reference/datamodel.html#object.__str__ I suggest reading this page: http://stackoverflow.com/questions/1307014/python-str-versus-unicode The Python documentation doesn't seem to cover __unicode__ very well... __repr__ may also be of interest. > When I print out for example a transaction i want to print out information of > objects that are nested into it. For example I would probably also to print > out the splits. > > I would like to have some function of the objects that are always called the > same way. In the end I would like to have something as easy as > > print object. If you implement __str__/__unicode__ methods, you can just do this: >>> print obj Hope this helps. Thanks, Forest -- Forest Bond http://www.alittletooquiet.net http://www.pytagsfs.org
signature.asc
Description: Digital signature
_______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel