Python Forum
why tuple instead of list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why tuple instead of list
#7
Funny thing, today I used namedtuples from header.
You can use starmap from itertools.

import csv
from collections import namedtuple
from pathlib import Path
from itertools import starmap


def read_nt(csv_file):
    with csv_file.open() as fd:
        reader = csv.reader(fd, delimiter=",")
        header = namedtuple("Header", next(reader))
        for row in starmap(header, reader):
            yield row


# you have to change the path
csv_file = Path.home() / "Desktop/akku.csv"
for row in read_nt(csv_file):
    print(row)
It would be nice, to have this inside the csv-module.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
why tuple instead of list - by Skaperen - Feb-14-2020, 11:50 PM
RE: why tuple insyead of list - by ndc85430 - Feb-15-2020, 10:31 AM
RE: why tuple insyead of list - by Skaperen - Feb-16-2020, 08:15 AM
RE: why tuple insyead of list - by buran - Feb-16-2020, 10:49 AM
RE: why tuple insyead of list - by Skaperen - Feb-17-2020, 12:12 AM
RE: why tuple insyead of list - by buran - Feb-17-2020, 08:22 AM
RE: why tuple instead of list - by DeaD_EyE - Feb-17-2020, 09:47 AM
RE: why tuple instead of list - by buran - Feb-17-2020, 09:56 AM
RE: why tuple instead of list - by Skaperen - Feb-18-2020, 01:00 AM
RE: why tuple instead of list - by DeaD_EyE - Feb-18-2020, 09:18 AM
RE: why tuple instead of list - by Skaperen - Feb-18-2020, 06:37 PM
RE: why tuple instead of list - by perfringo - Feb-18-2020, 08:15 PM
RE: why tuple instead of list - by Skaperen - Feb-19-2020, 02:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  strange difference between list() and tuple() using iter() Skaperen 1 1,786 Nov-01-2020, 06:49 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020