-1

i want to assert in python that the object has no particular field.

i have an object like below,

output = {
    'username': 'user',
    'hidden_fields': {
         'name': 'name1',
    }
}

but sometimes this hidden_fields property might not be there. so the object is like so,

output = {
    'username': 'user'
}

now how can i assert that output object has no property hidden_fields.

i am new to python. could someone help me with this. thanks.

stackuser
  • 253
  • 1
  • 2
  • 14

1 Answers1

0

Beware: You are handling a dict here, which is not exactly the same as an object.

To solve your problem, you could use this snippet:

if 'hidden_fields' not in output:
    print('No hidden fields')
else:
    print('Hidden fields found!')
Don Fruendo
  • 350
  • 3
  • 5