Skip to main content

All Questions

Tagged with
6 votes
1 answer
1k views

NamedTuple Class with ABC mixin

My problem is as follows: I want to create a class that inherits from typing.NamedTuple and another mixin which in an abstract class. Ideally I want to do something like this: from typing import * ...
hchw's user avatar
  • 1,406
0 votes
2 answers
38 views

Not able to assign a value to a variable

I've been playing around with namedtuples from collections in classes, and came across this simpler 'syntactic sugar' naming assignment, but when I assign foo to 009 and try to put it into the tuple ...
Tim Pozza's user avatar
  • 528
0 votes
1 answer
42 views

is it possible to get a new instance for namedtuple pushed into a dictionary before values are known?

It looks like things are going wrong on line 9 for me. Here I wish to push a new copy of the TagsTable into a dictionary. I'm aware that once a namedtuple field is recorded, it can not be changed. ...
RichWalt's user avatar
  • 502
0 votes
1 answer
45 views

Write all data from once CSV file to another -- but include new parsed geocoding data as additional fields

I'm trying to write a Python script that will take any CSV file, run it through a geocoder, and then write the resulting geocoding attributes (+ all the data from the original file) to a new csv file. ...
Matt BS's user avatar
  • 35
1 vote
0 answers
24 views

Strange inheritance of namedtuple methods in custom class [duplicate]

My goal is to create a class that behaves like a tuple except for the equality/inequality method(s), because I don't wantMyTuple(1, 2, 3) == (1, 2, 3) to be True and I want to use it for dictionary ...
koffein's user avatar
  • 1,872
11 votes
1 answer
2k views

How to apply a special methods 'Mixin' to a typing.NamedTuple

I love the typing.NamedTuple in Python 3.6. But there's often the case where the namedtuple contains a non-hashable attribute and I want to use it as a dict key or set member. If it makes sense that a ...
Damon Maria's user avatar
  • 1,031
4 votes
6 answers
3k views

Python mutable NamedTuple

I am looking for a struct like data structure I can create multiple instances from and have some type hinting without being immutable. So I have something like this: class ConnectionConfig(...
Jodo's user avatar
  • 4,733
1 vote
0 answers
880 views

typing.NamedTuple, abc.NamedTuple mixins in python 3.6.2?

I am new to python (3.6.2 is the version I am using). I am currently porting (trying to port) a DSL implementation from Scala to python for some projet in which python is imposed. So I am looking ...
remi's user avatar
  • 566
22 votes
1 answer
6k views

Understanding subclassing of JSONEncoder

I am trying to subclass json.JSONEncoder such that named tuples (defined using the new Python 3.6+ syntax, but it probably still applies to the output of collections.namedtuple) are serialised to JSON ...
Xophmeister's user avatar
  • 9,131
4 votes
2 answers
9k views

Namedtuple vs Dictionary

So I'm programming a game and I need a datatype that can store a multitude of variables ranging from lists, tuples, strings and integers. I'm torn between using either dictionaries or namedtuples. ...
Alice's user avatar
  • 628