[C++-sig] Re: Builtin python functions and the Object Wrapper
David Abrahams
dave at boost-consulting.com
Mon Jul 19 00:23:29 CEST 2004
"Brian Hall" <bhall at gamers-fix.com> writes:
> Say I want to implement the following python code in C++ using the object
> wrapper:
>
>
>
> def tb_lineno(tb):
>
>
>
> c = tb.tb_frame.f_code
>
> if not hasattr(c, 'co_lnotab'):
>
> return tb.tb_lineno
>
>
>
> tab = c.co_lnotab
>
> line = c.co_firstlineno
>
> stopat = tb.tb_lasti
>
> addr = 0
>
> for i in range(0, len(tab), 2):
>
> addr = addr + ord(tab[i])
>
> if addr > stopat:
>
> break
>
> line = line + ord(tab[i+1])
>
> return line
>
>
>
>
>
> How would I gain access to the len() and ord() builtin methods?
There's nothing in the library for those, though there should be.
len() is x.attr("__len__")(), but I think you need to go directly to
the Python/C API for "ord" (I'm not sure).
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
More information about the Cplusplus-sig
mailing list