Home/Support/Support Forum/import csv function
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

import csv function

0 votes
hi there..

i'm using ConnectPortX4 with Sensor LT.. i can't use import csv function.. error message..

"
File "WEB/python/test.py", line 5, in ?
import csv
ImportError: No module named csv"

is there any extra modules needed for this function?

thanks..
asked Sep 18, 2013 in Python by shahrule New to the Community (0 points)
edited Sep 18, 2013 by shahrule

Please log in or register to answer this question.

1 Answer

0 votes
You might be able to copy the csv.py in the c:\Python24\Lib folder on your PC onto the CPX4 in WEB/python and then get it to import, but you may end up needing to chase down more modules, or even possibly recreate them.

CSV files are pretty easy to work with in python using the standard string manipulation routines, both to parse and to put together.

For example, you can take the contents of a csv file and split it up into a list where each list element is a row by doing this:
Code:
rows = csv_data.split("\n")

You can then iterate over the rows and split up the data parts in each row by doing a simple call like
Code:
for row in rows: row_parts = row.split(",") for part in row_parts: pass #insert code to manipulate the data here

Putting it back together is pretty straight forward too if you have a list of data you want to assemble:
Code:
row = "" for data in data_list: row += data + "," row = row[:-1] + "\n"
answered Sep 18, 2013 by charliek Veteran of the Digi Community (408 points)
...