[IronPython] Help with Ops.GetAttr

Paul Turbett sls at iinet.net.au
Wed Feb 13 00:13:02 CET 2008


That did it, thanks!

Dino Viehland wrote:
> You could use Ops.TryGetAttr which doesn't take a context (and flows the default context in for you).
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Paul Turbett
> Sent: Tuesday, February 12, 2008 5:30 AM
> To: users at lists.ironpython.com
> Subject: [IronPython] Help with Ops.GetAttr
>
> Hi,
>
> I'm attempting to get an attribute from python object from C# using a
> method like this:
>
> public object GetAttr(object pyObject, string name)
> {
>    ICallerContext context = _pythonEngine.DefaultModule as ICallerContext;
>    object value = Ops.GetAttr( context, pyObject,
> SymbolTable.StringToId(name));
>    return value;
> }
>
> where _pythonEngine is a PythonEngine object, pyObject is a python
> object and name is the attribute I want to get.
>
> According to other posts I've seen, this should work, but the first line
> sets context to null. How to I get a valid context?
>
> It seems every way I've read about to get the context
> (DefaultContext.Default, GetModuleScope) is private, and therefore
> inaccessible.
>
> I'm using IPY 1.1.1
>
> TIA, Paul
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>   



More information about the Ironpython-users mailing list