Q:

pyQt, list passed to class init

I'm new to Python and pyQt.  I've got a class for a QDialog, and am passing a list of strings to this class in the init;
class Remove_Source(QtWidgets. QDialog, Ui_R_Source):
    def __init__(self, items=None):
        super(Remove_Source , self).__init__()
        self.ui = Ui_R_Source()
        self.ui.setupUi(self)
        self.setWindowTitle("Remove Source Folders")
        self.items = items or []
        for i in range(self.items.count()):
            self.ui.keep_window.addItem(self.items(i))
        self.exec()

The list is inaccessible within the class.  Anyone know what I'm doing wrong?  Thanks

A:

There are a few problems with your syntax.  Some points you need to check:
1) count has a different meaning for a Python list than it has for a QList.  The equivalent for a python list is len(self.items) (for example). 
2) The indexation operator (as in C++) is [].  The () would be a call operation (like in a function and its arguments).  In your code this means changing self.items(i) to self.items[i]. 
class Remove_Source(QtWidgets. QDialog, Ui_R_Source):
    def __init__(self, items=[]):                      # changed here
        super(Remove_Source , self).__init__()
        self.ui = Ui_R_Source()
        self.ui.setupUi(self)
        self.setWindowTitle("Remove Source Folders")
        self.items = items
        for i in range(len(self.items)):               # changed here
            self.ui.keep_window.addItem(self.items[i]) # changed here
        self.exec()

As a final note, although not invalid, using logical operators to provide a value might get you into trouble eventually.  In your case in here items or [] you are assuming that items has a truth value.  This is Ok if you are aware of what is happening but it can be dangerous otherwise.  In the code I gave the default value as an empty list [] and performed the normal attribution operation self.items = items.  I think its more explicit and safe (generally speaking). 
In any case try these modifications and see if it solves the problem.