Skip to content Skip to sidebar Skip to footer

Namedtuple Error

I am trying to serialize a Python object into JSON using namedtuple. But I get this error. Google does not help. Traceback (most recent call last): File 'cpu2.py', line 28, in <

Solution 1:

Here is a link to the documentation for namedtuple. You aren't initializing it properly.

How I'm guessing you should initialize it:

cpuInfo = collections.namedtuple('cpuStats', ['usr', 'nice', 'sys', 'idle'])

# In this case, usr=str(currentTime) + " " +str(cpuStats[0]) + " host=" + thisClient# You can figure the rest out...info = cpuInfo(usr='fill',
               nice='this',
               sys='your',
               idle='self')

Also, you might want to read this question which talks about serializing namedtuples in json.

Post a Comment for "Namedtuple Error"