[Ironpython-users] AttributeError when using methods from a DirectShowLib Interface

Sebastián Magrí sebasmagri at gmail.com
Wed Apr 8 15:04:08 CEST 2015


Hi!

I'm trying to use DirectShowLib for some basic media detection with the
`IMediaDet` interface. However, trying to use methods of the interface from
the instance throws `AttributeError` every time.

This is the script I'm using to test:

---
    import clr

    clr.AddReference('DirectShowLib')

    from DirectShowLib.DES import IMediaDet, DESError


    class Detector(IMediaDet):
        def __init__(self, *args, **kwargs):
            super(Detector, self).__init__(*args, **kwargs)


    mdet = Detector()

    print('Detector: {}\n'.format(mdet))
    print('Detector dir: {}\n'.format(dir(mdet)))
    print('Detector.put_Filename: {}\n'.format(mdet.put_Filename))
    print('Detector.put_Filename dir: {}\n'.format(dir(mdet.put_Filename)))
    print('Detector.put_Filename.Overloads: {}\n'.format(
        mdet.put_Filename.Overloads
    ))
    print('Detector.put_Filename.Overloads dir: {}\n'.format(
        dir(mdet.put_Filename.Overloads)
    ))
    print('Detector object is instance of IMediaDet: {}\n'.format(
        isinstance(mdet, IMediaDet)
    ))
    mdet.put_Filename('VID_20150207_133726.mp4')
---

And it prints the following information, finally throwing an error when I
try to use the method:

---
$ ipy -X:Debug -X:ShowClrExceptions -X:ExceptionDetail testdshow.py
Detector: <Detector object at 0x000000000000002B>

Detector dir: ['EnterBitmapGrabMode', 'Equals', 'GetBitmapBits',
'GetHashCode', 'GetSampleGrabber', 'GetType', 'MemberwiseClone',
'ReferenceEquals', 'ToString', 'WriteBitmapBits', '__class__',
'__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__',
'__hash__', '__init__', '__module__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__', '__weakref__', 'get_CurrentStream', 'get_Filename',
'get_Filter', 'get_FrameRate', 'get_OutputStreams', 'get_StreamLength',
'get_StreamMediaType', 'get_StreamType', 'get_StreamTypeB',
'put_CurrentStream', 'put_Filename', 'put_Filter']

Detector.put_Filename: <built-in method put_Filename of Detector object at
0x000000000000002B>

Detector.put_Filename dir: ['DeclaringType', 'Equals', 'GetHashCode',
'GetType', 'MemberwiseClone', 'Overloads', 'ReferenceEquals', 'Targets',
'ToString', '__call__', '__class__', '__cmp__', '__delattr__', '__doc__',
'__format__', '__ge__', '__get__', '__getattribute__', '__gt__',
'__hash__', '__init__', '__le__', '__lt__', '__module__', '__name__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__',
'__setattr__', '__sizeof__', '__str__', '__subclasshook__']

Detector.put_Filename.Overloads: {'put_Filename(self: Object#IMediaDet_4$4,
newVal: str) -> int\r\n': <built-in method put_Filename of Detector object
at 0x000000000000002B>}

Detector.put_Filename.Overloads dir: ['Equals', 'Function', 'Functions',
'GetHashCode', 'GetOverload', 'GetTargetFunction', 'GetType', 'Item',
'MemberwiseClone', 'ReferenceEquals', 'Targets', 'ToString', '__class__',
'__delattr__', '__doc__', '__format__', '__getattribute__', '__getitem__',
'__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

Detector object is instance of IMediaDet: True

'Detector' object has no attribute 'put_Filename'
   at
IronPython.Runtime.Operations.PythonOps.MissingInvokeMethodException(Object
o, String name)
   at IronPython.NewTypes.System.Object#IMediaDet_4$4.put_Filename(String
newVal)
   at
Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame
frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame
frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0
arg0, T1 arg1, T2 arg2, T3 arg3)
   at
System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite
site, T0 arg0, T1 arg1, T2 arg2)
   at __main__$15.__main__(FunctionCode $functionCode) in testdshow.py:line
22
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)
   at IronPython.Hosting.PythonCommandLine.RunFileWorker(String fileName)
   at IronPython.Hosting.PythonCommandLine.RunFile(String fileName)
AttributeError: 'Detector' object has no attribute 'put_Filename'
CLR Exception:
    MissingMemberException
:
'Detector' object has no attribute 'put_Filename'
---

I suspect it could be something related with overloading.

Any hints on why it's not working?

Best Regards,

-- 
Sebastián Ramírez Magrí
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20150408/df7149ea/attachment.html>


More information about the Ironpython-users mailing list