0

Im making a project in Python, using CPython3.4. I imported a dll which contains a ReadOnlyCollection. How can I get one item(at index) out of that list? I already tried to use .Item(index) and .Items but it says that:

"the object has no attribute "Item"

But when I use .Count it does give me the count. And the documentation says I could use both on this object. https://msdn.microsoft.com/en-us/library/ms132474(v=vs.110).aspx The dll is written in VB.net.

Can someone help me get one item out of that ReadOnlyCollection?

  • According to MSDN, ReadOnlyCollection.Items returns a List(of T). Since Items is the list in question, have you tried ReadOnlyCollection.Items.Item(index)? Long-winded, and shouldn't be necessary, but worth a try. – Jonathon Cowley-Thom Apr 10 '15 at 08:46
  • Just tried that, unfortunately that didn't work either :(, thx for helping anyway – Rowan Klein Gunnewiek Apr 10 '15 at 08:49
  • 1
    Perhaps post your Python code where you're instantiating the collection itself, because it sounds like something is null that shouldn't be. I won't be able to help there, as I'm not a Python programmer, but I'm sure someone with knowledge of Python will be along soon. – Jonathon Cowley-Thom Apr 10 '15 at 08:53
  • I could do that but im pretty sure I did that right, because when I call the collection.Count it gives me the correct awnser. So that means I'm sure something is in the list :) – Rowan Klein Gunnewiek Apr 10 '15 at 09:01
  • @RowanKleinGunnewiek how about `myReadOnlyCollection[i]`? (`i` is index of the item) that is the syntax in C#, may be the same for python – har07 Apr 10 '15 at 09:03
  • @har07 I already tried that, then I get the error : TypeError: unindexable object. So unfortunately that doesn't work :(, and when I try myReadOnlyCollection( i ) then i get the error: object is not callable – Rowan Klein Gunnewiek Apr 10 '15 at 09:12
  • @har07 Could you take a look at this question? http://stackoverflow.com/questions/29538031/call-dll-function-works-in-ironpython-doesnt-work-in-cpython3-4-gives-no-meth – Rowan Klein Gunnewiek Apr 10 '15 at 09:45

1 Answers1

1

Is this possible?

for i in ReadOnlyCollection:
    i.doSomething()

If it is possible you can find your object in this loop

Jesse
  • 64
  • 1
  • 7