Python Shell

Christoph Holtermann c.holtermann at gmx.de
Tue Jan 18 08:32:20 EST 2011


Hello Forest !
> 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/
Thank you very much for that advice.
>> 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.
Ok, I will have a look. I just hesitate to overwrite things I don't really understand ;-))
So I tend to start with adding a function of my own and then get down afterwards.
>> 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:
What would be the best way to control the amount of information that the functions
prints out. Would it be useful to have a config object which the functions accesses
or would it be more useful to use a parameter ?

In another program of mine i wrote __format__() functions which i provides with
an option verbose=(Boolean). But it's not possible to say format(object, verbose=True)
and i stick with print object.__format__(verbose=True) which is not actually very
handy ;-)
>>>> print obj
> Hope this helps.
Thanks !
> Thanks,
> Forest
regards,

Christoph


More information about the gnucash-devel mailing list