2

When I do the following:

configKeys = VALIDATION_DEFAULT_CONFIGURATION.keys()
print(configKeys)

But when I do this:

keys = [ x.value for x in configKeys ]

I get the following error:

 keys = [ x.value for x in configKeys ]
AttributeError: 'str' object has no attribute 'value'

Why is this so? How can I fix this error?

4
  • 1
    Most of those keys aren't members of your enum. They're just regular strings. Commented Dec 2, 2016 at 19:35
  • the x's are strings, not keys. Commented Dec 2, 2016 at 19:38
  • What is athena.enum.StrEnum? Commented Dec 2, 2016 at 19:40
  • I put your question back to it's original state. You edited out so much it was no longer a question and couldn't be answered. Commented Dec 2, 2016 at 20:13

1 Answer 1

3

Iterating over a dictionary yields its keys (which in your case are strings (str objects)). Strings don't have a value method or attribute.

If you want the values of your dict, you need to iterate over VALIDATION_DEFAULT_CONFIGURATION.values() , or if you want both keys and values at the same time, for (k, v) in VALIDATION_DEFAULT_CONFIGURATION.items():

Sign up to request clarification or add additional context in comments.

1 Comment

Some of the keys are enum members, which do have a value attribute (making likely but not certain guesses about athena.enum.StrEnum).

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.