import csv function

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…

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:


rows = csv_data.split("
")

You can then iterate over the rows and split up the data parts in each row by doing a simple call like


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:


row = ""
for data in data_list:
    row += data + ","
row = row[:-1] + "
"