Page 1 of 1

Reading in file from disk into variables

PostPosted: Wed Mar 24, 2021 6:38 pm
by dstrickler
I'd like to read in a CSV file, and store/update the data in variables. I' know how to store it (thanks to these forums), but I don't know now to read it in. I'm trying:
Code: Select all
import csv
with open('/Users/dstrickler/Sites/indigo/weathercat.csv', newline='') as csvfile:
   handle = csv.reader(csvfile, delimiter=',', quotechar='|')
   for row in handle:
      print(', '.join(row))
                # import into variables


While the code isn't working, I'm not sure if it's the CVS import code, or that I can't read from my own home directory.

What are the restrictions on reading from disk?

Re: Reading in file from disk into variables

PostPosted: Wed Mar 24, 2021 8:35 pm
by FlyingDiver
If you're calling that from an embedded script, you can't use print. Try:

Code: Select all
import csv
with open('/Users/dstrickler/Sites/indigo/weathercat.csv', newline='') as csvfile:
   handle = csv.reader(csvfile, delimiter=',', quotechar='|')
   for row in handle:
      indigo.server.log(', '.join(row))
                # import into variables

Re: Reading in file from disk into variables

PostPosted: Thu Mar 25, 2021 7:43 am
by dstrickler
Who new? Thanks for the tip! :D

Subtle code change around removing the "newline" variable, but got this working.

Code: Select all
import csv
with open('/Users/dstrickler/Sites/indigo/weathercat.csv') as csvfile:
   handle = csv.reader(csvfile, delimiter=',', quotechar='|')
   for row in handle:
      indigo.server.log(', '.join(row))
                # import into variables