Questions tagged [namedtuple]

namedtuple is a data structure provided by the Python collections module. It enables the creation of tuples with named elements (e.g., a Student tuple with the values (name, school, age) rather than a tuple with just two strings and an integer).

namedtuple is a data structure provided by the Python collections module. It enables the creation of tuples with named elements (e.g., a Student tuple with the values (name, school, age) rather than a tuple with just two strings and an integer).

Documentation: collections module in Python 3.

Recently, a declarative API for namedtuples is also provided by the typing module.

545 questions
0
votes
1 answer

Python dill: Pickle namedtuple doesnt seem to work

I have namedtuple inside a class. When pickling using dill, it complains the classic issue of not being able to find the namedtuple object at top module. import dill as pickle class NNRTMParse(object): def __init__(self,logfile)): …
rrkarts
  • 11
  • 2
0
votes
0 answers

Python3 -- ValueError in Windows but not in Linux

I had a python 3 script working great when running on Raspbian. I moved it to my Windows machine and downloaded all the necessary packages but I get a ValueError now: ValueError: ctypes objects containing pointers cannot be pickled The traceback…
linus72982
  • 1,418
  • 2
  • 16
  • 31
0
votes
1 answer

"'module' has no attribute" when working with namedtuples

I've run into a bit of a wall here, so I'm going to do my best to explain the issue. def playGames(jobQueue, ...): .... nextJob = jobQueue.get() ... def runPool(fens, timesetting, ...): ... for fen in fens: …
AndrewGrant
  • 786
  • 7
  • 17
0
votes
1 answer

Sorting a list of named tuples by field numercially

I'm fairly new to using python. I have a list of namedtuples which I would like to sort numerically by one of the fields. I currently have code that looks something like this: from collections import namedtuple testTuple = namedtuple("test", "name,…
Shani de Leeuw
  • 171
  • 1
  • 11
0
votes
1 answer

In Python, can I define a named tuple using typename?

I wonder why the third line in Snippet B would trigger an error. My understanding is in the second line in Snippet B (and A), I created a class variable (not a class instance) cls_obj whose type/class name is Duck. It's like class Duck(...): …
Nicholas
  • 2,560
  • 2
  • 31
  • 58
0
votes
1 answer

complexity of set of nameduple lookup

Hi in Python i have a namedtuple because i want to store a few values in the same object. A = namedtuple("A", "key1 key2 key3") I store those A's in a registry class which holds a set() class ARegistry(object): def __init__(self): …
Robin van Leeuwen
  • 2,625
  • 3
  • 24
  • 35
0
votes
1 answer

How to get a sorted list of namedtuples' attributes

I am totally lost as to why I keep getting errors. I am trying to print the titles of the books listed in alphabetical order using sorted(). I keep getting this error: sorted(BSI, key=list(Book)) TypeError: 'type' object is not iterable Then this…
0
votes
3 answers

Python namedtuple in a boolean context

When a Python tuple is used in a boolean context, it is considered True if and only if it is not empty. Does the same apply to instances of collections.namedtuple?
user200783
  • 13,722
  • 12
  • 69
  • 135
0
votes
2 answers

retrieving namedtuple value from string

I have created a namedtuple like this. Named_Tuple_1 = namedtuple("Coordinates", ["x", "y", "z"], verbose=False, rename=False) Point_1 = Named_Tuple_1(x=1, y=1, z=1) Point_2 = Named_Tuple_1(x=2, y=2, z=2) Point_3 = Named_Tuple_1(x=3, y=3, z=3) I…
GrandJoss
  • 27
  • 1
  • 7
0
votes
1 answer

Need help sorting a namedtuple and then printing the name of each namedtuple in Python

hello I am having some difficulty getting a function to work. I was given a list (RL) of restaurants in namedtuples and was asked to create a function that sorts the list by alphabetically order and then returns only the name of each…
A.G
  • 31
  • 5
0
votes
3 answers

Creating namedtuple instance from already set values

I have a namedtuple like this course_summary_struct = namedtuple( 'CourseSummary', ['id', 'display_name', 'location', 'display_coursenum', 'display_organization'] ) I want to update the the namedtuple dynamically…
A.J.
  • 8,557
  • 11
  • 61
  • 89
0
votes
1 answer

Python get values in dictionary inside another dictionary

I have the following data get by JSON: EVENT = { 'eventid': '11828346', 'acknowledges': [{'alias': 'user1', 'name': 'userXYZ'}], 'objectid': '25946', 'clock': '1444051689', 'object': '0', …
Joao Vitorino
  • 2,976
  • 3
  • 26
  • 55
0
votes
1 answer

namedtuple pickling fails when variable name doesn't match typename

The python code below fails with the error pickle.PicklingError: Can't pickle : it's not found as __main__.SpecialName import pickle from collections import namedtuple different_SpecialName = namedtuple('SpecialName',…
eqzx
  • 5,323
  • 4
  • 37
  • 54
0
votes
2 answers

Tuple with named elements

In python 2.7.10, sys.version_info from the sys module is: sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0) What python type is this? It appears to be some sort of a tuple with named elements, and you can refer to…
andro
  • 901
  • 9
  • 20
0
votes
1 answer

What's @classmethod do outside of a class in Python?

In the below code, if the @classmethod annotation is present, the inner def new() is allowed to stand in for the target's __new__() -- but the class is passed twice. If @classmethod is removed then we get an error like "". What is @classmethod doing…
solidsnack
  • 1,631
  • 16
  • 26