Ask a Question

Python cluelessness with lists

Occasional Contributor

Python cluelessness with lists

Hi, I'm trying to transition from VBScript to Python and having some trouble understanding lists in Python.  What I'm trying to do is find all the comboboxes in a dialog and add them to a list.  Once they are in the list I iterate through the list setting the indexes of the comboboxes.  Unfortunately it's not working. 


Here is a simplified version of the code omitting the iteration through the list with a 'for' statement:


dlg = some_dialog

combos = [(dlg.FindAllChildren(QtClassName,"OnOneComboBox",7))]



When I run the code I get this error:

AttributeError: 'SafeArrayWrapper' object has no attribute 'QComboBox_setCurrentIndex'


What is this "SafeArrayWrapper" business? 


Many thanks, John

Valued Contributor

You said you are creating a list ...

So what do you suppose to do with combos[0].QComboBox_setCurrentIndex(1) ?

what the message saying is there is no attribute call "QComboBox_setCurrentIndex(1)" in lists class/object


what index are you going to set?   


for Iterate you can use combos[i] in for loop which iterate from 0 to len(combos)


to understand python lists read this and this



Occasional Contributor

Hi, thanks for the reply.  I'm expecting combos[0] to return the combobox object at index zero in the combos list.  Provided that happens QComboBox_setCurrentIndex(1) will select the second item in the combobox.  


The problem is I'm not getting an object back with combos[0].  Instead of the combobox object I'm getting a "SafeArrayWrapper".  If I don't get the combobox back then QComboBox_setCurrentIndex(1) will obviously fail.


Also, I can't find any information in Python documentation regarding a "SafeArrayWrapper" object.  My assumption is SafeArrayWrapper is a SmartBear/TestComplete construct that doesn't exist natively in Python.  I could be wrong about that though.



Community Hero



Try to remove square brackets from your statement:


combos = dlg.FindAllChildren(QtClassName,"OnOneComboBox",7)

Otherwise you will receive array in array, something like:


[[obj1, obj2, obj3]]
Occasional Contributor

Hi, thanks for the tip.  Removing the brackets works but later when I want to append to the combos list/array it's not working.  Following on from my example I tried something like this:

combos.append (some_other_combo_here)


That gives me the familiar error:  "AttributeError" 'SafeArrayWrapper' object has no attribute 'append'.


Any idea how I can successfully append to combos?




Occasional Contributor

It looks like I figured it out.  I changed :

combos = [(dlg.FindAllChildren(QtClassName,"OnOneComboBox",7))]




combos = list(dlg.FindAllChildren(QtClassName,"OnOneComboBox",7))


Removing the brackets per your suggestion and adding "list" did the trick.  Now setting the index is working and I'm able to append to the list.




FindAllChildren() returns list anyway. You can omit adding a list():


combos = dlg.FindAllChildren(QtClassName,"OnOneComboBox",7)


Occasional Contributor

I tried it without List() and iterating through the list and setting the index works fine.  However, if I try to append to the list I get the SafeArrayWrapper error message.  When I use List() the append works as expected.  I have no clue why.


As you suggested the result should be the same but in practice it's not.

New Member

I have a problem with VBScript for a long time. Wondering that there are some people still using it!

However, I found this tutorial very useful for Python lists.



New Contributor

This is another very good reference on what is a list in Python. It cites several examples that can guide to many related problems.

Showing results for 
Search instead for 
Did you mean: