1

I have an object self.config which has some variables, I would like to first check if a variable ('db_password') exist in self.config and if it exists then modify the variable value something like self.config.db_password = 'modified values' . following is the python code

    if hasattr(self.config, enc_variable):
        setattr(self.config, enc_variable, f.decrypt(self.config.enc_variable.encode('ascii')).decode('ascii'))

AttributeError: 'Config' object has no attribute 'enc_variable'

1 Answer 1

1

This part is buggy:

self.config.enc_variable

It should be

getattr(self.config, enc_variable)

Or

self.config.db_password
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.