xralf
xralf

Reputation: 3642

named tuples in a dictionary

I'm trying to use named tuples as follows:

from collections import namedtuple
thermometer = namedtuple('thermometer', 'name, max, min')
mac_dict = {
            "1234" : thermometer("warehouse1", 15, 17),
            "123B" : thermometer("warehouse2", 11, 19),
            "124C" : thermometer("serverroom", 12, 34)
           }

mac_address = "1234"
print mac_dict[mac_address].thermometer.max

But this ends with:

AttributeError: 'thermometer' object has no attribute 'thermometer'

Can I fix it somehow?

Upvotes: 0

Views: 42

Answers (1)

Pynchia
Pynchia

Reputation: 11590

As the error says

mac_dict[mac_address]

is the thermometer.

Just address its max with

mac_dict[mac_address].max

Upvotes: 1

Related Questions