Skip to content

deque reader is printing data as empty

An answer to this question on Stack Overflow.

Question

When I run the below script locally I can see data getting printed from the trend.csv file, but when I run the script on a server all the values turn up empty.

I can see that there is content in the trend.csv file (it is not empty).

How do I make sure that this is really opening the .csv file?

Does any one have any ideas on how to debug this or overcome this problem?

with open('//data/loc/scripts/trend.csv','rU') as fin:
  reader = csv.reader(fin)
  data   = deque(reader,8)
print data

On the server, I get:

deque([], maxlen=8)

Locally, I get:

deque([['06/27/2013', '5'], ['06/27/2013', '8'], ['06/27/2013', '8'], ['06/27/2013', '8'], ['06/27/2013', '8'], ['06/27/2013', '8']], maxlen=8)

Answer

Try to break down the problem:

  1. Check the file on both your local machine and the server: is it really non-empty?

  2. Try reading the file in using some simpler method.

In the latter case, this is one possible approach:

with open('//data/loc/scripts/trend.csv','rU') as fin:
  print(fin.read())
  1. Check the encoding of the file: is it the same on both machines? Perhaps this is why the CSV reading is failing.