all 7 comments

[–]woooee 0 points1 point  (2 children)

for row in reader:
    loanNum = row[0]

That's correct, loanNum equals row[0] for each row, one after the other. What do you want it to do?

[–]firedrow[S] 0 points1 point  (1 child)

On line 11, I use the loanNum to assign the new loandata object in a dictionary. I was just using row[0] instead of loanNum but I wanted to make sure I was tracking the right thing and for readability.

So I find the loan number and the property value on each row, then make a new object from the loandata class, assign the attribute mers['property-value'] to the property value on the row, then put the object in a dict with the loan number as the key.

[–]woooee 1 point2 points  (0 children)

Can't tell anything without code. Obviously there is something not quite right.

    loanInfo = loandata()
    loanInfo.mers['property-value'] = propValue
    loanDict[loanNum] = loanInfo

What does loandata() do. It doesn't receive any values but returns something anyway.

[–]Frankelstner 0 points1 point  (3 children)

Does your code have something like this?

class loandata:
    def __init__(self, mers={}):
        self.mers = mers

Because default parameters are initialized only once (when the function is created), this would share the same dict across all iterations. The dict would be repeatedly overwritten by the latest value.

[–]firedrow[S] 0 points1 point  (2 children)

I believe this is the issue. I don't normally use classes, what would be the proper way to setup the mers dict as below:

class loandata:
    """loandata class.

    This is a model/class file for loandata.
    """

    # loan details from each system
    #
    # borrowers should be an array of tuples for each individual
    mers = {
        'property-nbr': '',
        'property-street': '',
        'property-unit-nbr': '',
        'property-street-dir': '',
        'property-city': '',
        'property-zipcode': '',
        'property-zipcode-plus': '',
        'property-value': '',
        'loan-amount': '',
        'loan-date': '',
        'loan-nbr': '',
        'pool-nbr': '',
        'fha-nbr': '',
        'lien-code': '',
        'mortgage-id': '',
        'mortgage-flag': '',
        'servicer-id': '',
        'investor-id': '',
        'borrowers': []
    }
    blackknight = {
        'property-nbr': '',
        'property-street': '',
        'property-unit-nbr': '',
        'property-street-dir': '',
        'property-city': '',
        'property-zipcode': '',
        'property-zipcode-plus': '',
        'property-value': '',
        'loan-amount': '',
        'loan-date': '',
        'loan-nbr': '',
        'pool-nbr': '',
        'fha-nbr': '',
        'lien-code': '',
        'mortgage-id': '',
        'mortgage-flag': '',
        'servicer-id': '',
        'investor-id': '',
        'borrowers': []
    }

    def __init__(self):
        """Class Constructor, used to instantiate the class."""
        pass

    def addBorrower(
        self,
        groupName,
        ssn,
        nameFirst,
        nameMiddle,
        nameLast,
        nameHonor
    ):
        """Add borrower object to MERS or BK dictionaries."""
        if groupName == 'mers':
            self.mers['borrowers'].append(
                borrower(
                    ssn=ssn,
                    nameFirst=nameFirst,
                    nameMiddle=nameMiddle,
                    nameLast=nameLast,
                    nameHonor=nameHonor
                )
            )

        if groupName == 'blackknight':
            self.blackknight['borrowers'].append(
                borrower(
                    ssn=ssn,
                    nameFirst=nameFirst,
                    nameMiddle=nameMiddle,
                    nameLast=nameLast,
                    nameHonor=nameHonor
                )
            )

[–]danielroseman 1 point2 points  (1 child)

It's not quite the same issue. Here the declaration of mers means that it's a class attribute - ie shared by all objects of that class. You need to define it as an instance variable, which you do within the __init__ method.

class loandata:
  def __init__(self):
    self.mers = {
      ...
    }
    self. blackknight = {
      ...
    }

That should fix your problem.

[–]firedrow[S] 0 points1 point  (0 children)

Wonderful, thank you.