0

I'm struggling to break the following error down: "AttributeError: 'builtin_function_or_method' object has no attribute 'fieldnames'"

I'm using the following code, which DOES work on Windows, unlike Linux... which is an issue, because I have to get this working on an AWS server enrolled with Linux.

import csv
from csv import reader

with open('/home/maurits/PolisCheck/check/PolisLists/PolisCheck.csv', newline='') as csvfile:
    PolisCheck = csv.DictReader(csvfile)
    for row in PolisCheck:
        ([col + '=' + row[col] for col in reader.fieldnames])

Thanks in advance!

Maurice
  • 11
  • 2
  • 1
    Are you quite sure this works under Windows, and that you didn't mean `PolisCheck.fieldnames`? – Passerby Feb 18 '22 at 09:49
  • Hi Passerby, I'm 100% sure this code worked for me on Windows, although it was on the PC in my office. I'm running the code on the same environment (Pycharm, Python 3.11) and guess what: it doesn't work anymore.. ` PolisCheck.fieldnames ` is indeed the correct statement, though my code doesn't work like it used to haha. – Maurice Feb 18 '22 at 10:41
  • Please can you add a few rows from your CSV file (in text format) to the question and show what your expected output is going to be – Martin Evans Feb 18 '22 at 11:48
  • Hi Martin, the rows look as following (""" for demarcation): """Klantnr., Huisnr., Postcode, Polisnr.""" """105823,43,9741TG,11354853""" """105004,36,2508CX,11443173""" """10540,12,1271XX,11348121""" """105675,66 a,6522XJ,11359642""" What I'm trying to reach is whenever the user input (Polisnr.) corresponds with a row in the CSV file, the Python script displays all available information about the row (with a return statement..?). – Maurice Feb 18 '22 at 13:05

0 Answers0