Re: Assistance with importing a csv into a PostgreSQL database - Mailing list pgsql-novice

From Michael Wood
Subject Re: Assistance with importing a csv into a PostgreSQL database
Date
Msg-id 5a8aa6680908060535m6c8ed0e5g9dd4441a60128e36@mail.gmail.com
Whole thread Raw
In response to Re: Assistance with importing a csv into a PostgreSQL database  (Intengu Technologies <sindile.bidla@gmail.com>)
List pgsql-novice
2009/8/6 Intengu Technologies <sindile.bidla@gmail.com>:
> Fellow South African indeed ;)
>
> I run windows and have installed Python - forgive me I am not a
> programmer and my data is on an external HD.
> I then modified your script to be like this

You will need double backslashes if you specify the full path.

e.g.:
infile = open("F:\\data\\myfile.csv")

This is because the backslash is a quoting character in Python (and
many other languages).

If this still doesn't work, you should be able to change back to just
filenames instead of the full path, put the script and myfile.csv in
the same directory and then double-click on the script.

> import csv
>>
>> def get_csv_writer(filename):
>>     return csv.writer(open(filename, "w"), quoting=csv.QUOTE_ALL)
>>
>> infile = open("F:\data\myfile.csv")
>> table = {"1": get_csv_writer("F:\data\myfiletable1.csv"),
>>          "2": get_csv_writer("F:\data\myfiletable2.csv"),
>>          "3": get_csv_writer("F:\data\myfiletable3.csv"),
>>          "4": get_csv_writer("F:\data\myfiletable4.csv"),
>>          "5": get_csv_writer("F:\data\myfiletable5.csv"),
>>          "6": get_csv_writer("F:\data\myfiletable6.csv")}
>>
>> reader = csv.reader(infile)
>> for line in reader:
>>     table[line[0]].writerow(line[1:])
>
> I then saved this as importcsv.py
>
> Opened it in python IDE, but I am getting syntax errors.

If the advice above does not help, send the syntax errors.  This is of
course not a Python support list, but I hope nobody minds too much :)

--
Michael Wood <esiotrot@gmail.com>

pgsql-novice by date:

Previous
From: Michael Wood
Date:
Subject: Re: Assistance with importing a csv into a PostgreSQL database
Next
From: Tim Greenwood
Date:
Subject: Checking my understanding of locales