Python Forum
csv.reader(): Limit the number of columns read in Windows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
csv.reader(): Limit the number of columns read in Windows
#3
Try it this way:
import csv

file1 = '/home/pedro/winter2020/20PY/dumpFiles/attendanceWinter2020_20PY.csv'
with open(file1) as fp:
    crdr = csv.reader(fp, delimiter = ',')
    for data1 in crdr:
        print(data1)
or if there is a header and you want a dictionary item:
import csv

file1 = '/home/pedro/winter2020/20PY/dumpFiles/attendanceWinter2020_20PY.csv'
with open(file1) as fp:
    crdr = csv.DictReader(fp, delimiter = ',')
    for row in crdr:
        for key, value in row:
            print(f"{key}: {value}")
Pedroski55 likes this post
Reply


Messages In This Thread
RE: csv.reader(): Limit the number of columns read in Windows - by Larz60+ - Dec-25-2020, 11:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Read complete windows registry? fredep57 3 981 Mar-15-2023, 08:14 PM
Last Post: buran
  Read directory listing of files and parse out the highest number? cubangt 5 2,450 Sep-28-2022, 10:15 PM
Last Post: Larz60+
  xml simple reader kucingkembar 2 1,087 Aug-19-2022, 08:51 PM
Last Post: kucingkembar
  Having strange results from an RFID HID card reader - I'm stuck orbisnz 1 1,522 Mar-28-2022, 08:20 AM
Last Post: Larz60+
  Thoughts on interfacing with a QR code reader that outputs keystrokes? wrybread 1 1,518 Oct-08-2021, 03:44 PM
Last Post: bowlofred
  Remove Specific Columns when the number of columns is greater than a specific value CuriousOne 0 1,341 Sep-09-2021, 09:17 PM
Last Post: CuriousOne
  NFC reader code help johnroberts2k 1 2,629 Jul-02-2021, 08:43 PM
Last Post: deanhystad
  [Solved] Using readlines to read data file and sum columns Laplace12 4 3,629 Jun-16-2021, 12:46 PM
Last Post: Laplace12
  Read strings and numbers in columns from a file suvadip 4 2,965 Aug-11-2020, 09:37 PM
Last Post: suvadip
  Closing Files - CSV Reader/Writer lummers 2 2,640 May-28-2020, 06:36 AM
Last Post: Knight18

Forum Jump:

User Panel Messages

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