Re: Keeping a list of records with named fields that can be updated

2022-12-19 Thread songbird
Peter Otten wrote: ... > I recommend that you use a dataclass /instead/ of a namedtuple, not > both. However, for a dataclass with the same fields in the same order as > in your namedtuple the conversion is trivial: > > Create compatible namedtuple and dataclass types: > > >>> NTRow = namedtuple("N

Re: Keeping a list of records with named fields that can be updated

2022-12-19 Thread Peter Otten
On 18/12/2022 16:44, songbird wrote: Peter Otten wrote: ... While I think what you need is a database instead of the collection of csv files the way to alter namedtuples is to create a new one: from collections import namedtuple Row = namedtuple("Row", "foo bar baz") row = Row(1, 2, 3) row._r

Re: Keeping a list of records with named fields that can be updated

2022-12-19 Thread Peter Otten
On 17/12/2022 20:45, Albert-Jan Roskam wrote: On Dec 15, 2022 10:21, Peter Otten <__pete...@web.de> wrote: >>> from collections import namedtuple >>> Row = namedtuple("Row", "foo bar baz") >>> row = Row(1, 2, 3) >>> row._replace(bar=42) Row(foo=1, bar=42, baz=3)

Re: Keeping a list of records with named fields that can be updated

2022-12-18 Thread songbird
Peter Otten wrote: ... > While I think what you need is a database instead of the collection of > csv files the way to alter namedtuples is to create a new one: > > >>> from collections import namedtuple > >>> Row = namedtuple("Row", "foo bar baz") > >>> row = Row(1, 2, 3) > >>> row._replace(bar=4

Re: Keeping a list of records with named fields that can be updated

2022-12-17 Thread Albert-Jan Roskam
On Dec 15, 2022 10:21, Peter Otten <__pete...@web.de> wrote: >>> from collections import namedtuple >>> Row = namedtuple("Row", "foo bar baz") >>> row = Row(1, 2, 3) >>> row._replace(bar=42) Row(foo=1, bar=42, baz=3) Ahh, I always thought these are undocumen

Re: Keeping a list of records with named fields that can be updated

2022-12-15 Thread songbird
Peter Otten wrote: > > While I think what you need is a database instead of the collection of > csv files the way to alter namedtuples is to create a new one: the files are coming from the web site that stores the accounts. i already have manually created files from many years ago with some of

Re: Keeping a list of records with named fields that can be updated

2022-12-15 Thread Weatherby,Gerard
I have a lot of NamedTuples in my codebase, and I now add new ones never. They were a good option prior to Python 3.7 but dataclasses are much easier to work with and are almost a drop-in substitute. A combination of a default dictionary and a dataclass might meet your needs: import collectio

Re: Keeping a list of records with named fields that can be updated

2022-12-15 Thread Peter Otten
On 14/12/2022 19:50, songbird wrote: I'm relatively new to python but not new to programming in general. The program domain is accounting and keeping track of stock trades and other related information (dates, cash accounts, interest, dividends, transfers of funds, etc.) Assume that

Re: Keeping a list of records with named fields that can be updated

2022-12-14 Thread Thomas Passin
Dictionaries and sets are your friends here. On 12/14/2022 1:50 PM, songbird wrote: I'm relatively new to python but not new to programming in general. The program domain is accounting and keeping track of stock trades and other related information (dates, cash accounts, interest, divid