Reading in file from disk into variables

Posted on
Wed Mar 24, 2021 6:38 pm
dstrickler offline
User avatar
Posts: 340
Joined: Oct 08, 2010
Location: Boston, MA

Reading in file from disk into variables

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?

Dave

Posted on
Wed Mar 24, 2021 8:35 pm
FlyingDiver offline
User avatar
Posts: 7190
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Reading in file from disk into variables

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

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Mar 25, 2021 7:43 am
dstrickler offline
User avatar
Posts: 340
Joined: Oct 08, 2010
Location: Boston, MA

Re: Reading in file from disk into variables

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

Dave

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests