Python bindings: Account.getName() raises TypeError

Derek Atkins warlord at MIT.EDU
Tue Mar 18 09:30:11 EDT 2014

John Ralls <jralls at> writes:

> On Mar 17, 2014, at 10:52 AM, Derek Atkins <warlord at> wrote:
>> John Ralls <jralls at> writes:
>>>> TypeError: in method 'xaccAccountGetName', argument 1 of type
>>>> Account const *'
>> [snip]
>>> The signature of xaccAccountGetName is const char* xaccAccountGetName
>>> (const Account *); the const was added in 2005. A "const Account *" is
>>> not the same as an "Account const *": The former means that the
>>> contents of the pointer won't change, the latter means that the
>>> pointer itself won't change (see
>>> Somewhere in the SWIG-generated Python-to-C translation code the
>>> argument type is wrong, but it's not directly in the stack trace from
>>> Python. It's more likely due to a change in SWIG than to a change in
>>> GnuCash.
>> Could it be a const v non-const issue?  I.e., if python has an Account*
>> object (non-const) does it realize that it can pass it to a function
>> that is asking for a const object (either const Account* or Account
>> const * -- doesn't matter)?  C certainly knows this, but it sounds like
>> Python might not.
> At that level, it’s all C; in this case it’s C generated by SWIG
> instead of written by hand, but it’s still C.
> Python doesn’t even have the concept of const, and its handling of
> types is deliberately generic: If an object has a member with the
> right name, it’s happy.

Is the TypeError coming from Python or coming from the SWIG bindings?
The fact that Python doesn't know about 'const' is exactly my point.  It
probably sees "Account *" and "Account const *" as two distinct types,
which would explain why it's complaining about the "Type Error".

> Regards,
> John Ralls

       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL:    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available

More information about the gnucash-devel mailing list