vendredi 8 janvier 2021

How can I compare the value of an object's attribute in Python?

So, I'm using mongoDB and my queries return an array of objects. The objects look like this:

   {
        '_id': ObjectId('5ff891bc20cb7d29dc1d836c'),
        'Model': 'X1150',
        'Platform': 'Server',
        '# of CPU Cores': 4,
        '# of Threads': 4
    }

Let's say I store this specific document in the variable doc

Now, I want to be able to compare the 'Platform' attribute with a string. In JavaScript, for example, I would do:

if (doc.Platform == 'Server') return 1;

but it doesn't seems to work in python (maybe because the attribute is a string?). How can I make this comparison correctly?

Thanks!

Aucun commentaire:

Enregistrer un commentaire