0

I have the following code snippet:

class BaseUserAccount(object):
    def __init__(self):
        accountRefNo = "RefHDFC001"
        FIType = "DEPOSIT"
        pan = "AFF34964FFF"
        mobile = "9822289017"
        email = "[email protected]"
        aadhar = "5555530495555"


class TestUserSavingsAccount(BaseUserAccount):
    def __init__(self):
        super().__init__()
        accountNo = "HDFC111111111111"
        accountTypeEnum = "SAVINGS"

    def test_create_account(self):
        request_body = """\
            <UserAccountInfo>
                <UserAccount accountRefNo="{}" accountNo="{}"
                accountTypeEnum="{}" FIType="{}">
                    <Identifiers pan="{}" mobile="{}" email="{}" aadhar="{}"></Identifiers>
                </UserAccount>
            </UserAccountInfo>
        """.format(self.accountRefNo, self.accountNo, self.accountTypeEnum,
                self.FIType, self.pan, self.mobile, self.email, self.aadhar)

If I run this code in the interactive shell:

>>> t = TestUserSavingsAccount()
>>> t.accountRefNo
AttributeError: 'TestUserSavingsAccount' object has no attribute 'accountRefNo'
>>> t.accountNo
AttributeError: 'TestUserSavingsAccount' object has no attribute 'accountNo'

Seeing the above behavior, it seems like the super is neither setting up values from the base class and neither the attributes of the child (accountNo, accountTypeEnum) are being set.

1 Answer 1

2

The way you wrote only assign those values to local variables. You need to initialize attributes of the self object instead:

class BaseUserAccount(object):
    def __init__(self):
        self.accountRefNo = "RefHDFC001"
        self.FIType = "DEPOSIT"
        self.pan = "AFF34964FFF"
        self.mobile = "9822289017"
        self.email = "[email protected]"
        self.aadhar = "5555530495555"


class TestUserSavingsAccount(BaseUserAccount):
    def __init__(self):
        super().__init__()
        self.accountNo = "HDFC111111111111"
        self.accountTypeEnum = "SAVINGS"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.