Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV writer - no output??
#1
I am unable to use Pandas on a Python 2.7 environment.
I am appending all output into a new file using the csv library.
I am having to use Visual Code, which appears a bit fuzzy.
Yesterday, I didn't get any errors with the same code???

Now I am getting a writer error:
writer.writerow(row)
File "C:\python38\lib\csv.py", line 154, in writerow
return self.writer.writerow(self._dict_to_list(rowdict))
File "C:\python38\lib\csv.py", line 147, in _dict_to_list
wrong_fields = rowdict.keys() - self.fieldnames
AttributeError: 'list' object has no attribute 'keys'

I would appreciate any pointers.
Thanks,
Clive

##### START    
for filename in glob.glob(Path+'\*.jpg'):
    #print(filename)
    with open(latlongfile, 'w' ) as csvfile:
    #### Get Filename, lat/Long
        #### Returns: Latitude, Longitude and Altitude
        geo_tag = gpsphoto.getGPSData(filename)
        #reader = csv.DictReader(csvfile)     
        print(geo_tag)
        latitude = geo_tag.get('Latitude')
        longitude = geo_tag.get('Longitude')
        #for row in reader:
        print(row['filename'], row['latitude'], row['longitude'])
        #print(filename, latitude, longitude)
        writer = csv.DictWriter(csvfile, headersCSV)
        # Pass the data in the dictionary as an argument into the writerow() function
        writer.writerow(row)
        # Close the file object
        csvfile.close()
#### END
Larz60+ write Mar-28-2022, 06:36 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
CSV writer - no output?? - by Clives - Mar-28-2022, 05:25 PM
RE: CSV writer - no output?? - by Larz60+ - Mar-28-2022, 06:43 PM
RE: CSV writer - no output?? - by Clives - Mar-29-2022, 01:23 PM
RE: CSV writer - no output?? - by Clives - Mar-29-2022, 01:44 PM
RE: CSV writer - no output?? - by Larz60+ - Mar-29-2022, 03:09 PM
RE: CSV writer - no output?? - by Clives - Mar-30-2022, 03:51 PM
RE: CSV writer - no output?? - by Clives - Mar-30-2022, 04:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Csv writer meaning of quoting mg24 2 2,133 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  [split] NameError: name 'csvwriter' is not defined. Did you mean: 'writer'? cathy12 4 5,888 Sep-01-2022, 07:41 PM
Last Post: deanhystad
Sad pandas writer create "corrupted" file freko75 1 5,042 Jun-14-2022, 09:57 PM
Last Post: snippsat
  Closing Files - CSV Reader/Writer lummers 2 3,931 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