[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #SXM-109553]: latest obs to CSV?


So what error message is complaining about is that youâre trying to write a 
`str` (text), but the file is expecting to be given `bytes` (binary data) to 
write. In this case I think you *should* be writing text so you should change 
your open line to:

    with open("C:\\Users\\Public\\Documents\\outfile.csv", 'w') as outcsv:

Note the change from âwbâ to âwâ, which changes from opening the file 
for binary i/o to text i/o. I expect that change should get you working.

Hope it helps!


> Hi Ryan,
> The error that I get when trying to output the station temp data is the 
> following:
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> <ipython-input-5-9ded64172cc7> in <module>
> 1 with open("C:\\Users\\Public\\Documents\\outfile.csv", 'wb') as outcsv:
> 2         writer = csv.writer(outcsv,delimiter=',')
> ----> 3         writer.writerow(["lat", "long", "temp", "station"])
> 4         for i in data:
> 5             writer.writerow(i)
> TypeError: a bytes-like object is required, not 'str'
> Here is an example of how the data looks:
> (42.36056, -71.01056, 41.0, 'KBOS')
> Again, thank you for your time/any help!
> Justin
> -----Original Message-----
> From: Unidata Python Support [mailto:address@hidden
> Sent: Monday, November 12, 2018 4:22 PM
> To: Perry, Justin B
> Cc: address@hidden
> Subject: [python #SXM-109553]: latest obs to CSV?
> Hi,
> No worries! What's the actual error message you receive?
> Ryan
> > Hi again,
> >
> > The error that I was receiving yesterday seems to have resolved somehow.  I 
> > apologize!
> >
> > However, I am still having a slight issue with the next step after that.  I 
> > am trying to write the Lat, Lon, Temp, Station ID to a CSV file and I keep 
> > getting an error.
> >
> > I'm essentially trying to take the data from the surface temp map and just 
> > create a list of the data as well.

Ticket Details
Ticket ID: SXM-109553
Department: Support Python
Priority: Low
Status: Closed
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.