Re: Importing Excel/CVS into Database

2007-08-24 Thread Boris Samorodov
On Fri, 24 Aug 2007 22:27:13 - robo wrote: > Wow, your tip works like a charm. Glad to be helpful! > Do you personally know of a good tutorial that teaches things like Sorry, I don't. :-( > this? I'd like to read them. WBR -- bsam --~--~-~--~~~---~--~~

Re: Importing Excel/CVS into Database

2007-08-24 Thread robo
Wow, your tip works like a charm. Do you personally know of a good tutorial that teaches things like this? I'd like to read them. Thanks, - robo On Aug 24, 2:54 pm, Boris Samorodov <[EMAIL PROTECTED]> wrote: > Hi, All! > > On Fri, 24 Aug 2007 21:05:07 - robo wrote: > > > How would I catch

Re: Importing Excel/CVS into Database

2007-08-24 Thread Boris Samorodov
Hi, All! On Fri, 24 Aug 2007 21:05:07 - robo wrote: > How would I catch a blank/empty line? > I've googled and tried: > if not line.strip(): > print "skipping blank line" > continue > if line.strip() == '': > print "skipping blank line" > continue I used to do: - line =

Re: Importing Excel/CVS into Database

2007-08-24 Thread robo
How would I catch a blank/empty line? I've googled and tried: if not line.strip(): print "skipping blank line" continue if line.strip() == '': print "skipping blank line" continue the script keeps spewing data into the DB, but doesn't seem like its catching blank/empty lines because

Re: Importing Excel/CVS into Database

2007-08-24 Thread robo
Good news guys, this code is working for me: import MySQLdb import csv def imports(): db = MySQLdb.connect(user='...', db='...', passwd='...', host='...') cursor = db.cursor() file = "C:\\test_import.txt" for i, line in enumerate(open(file)): if i == 0: continue

Re: Importing Excel/CVS into Database

2007-08-23 Thread Amirouche
## data.csv ## "name","symbol","value","change","mktcap","volume","open","high","low" "Google Inc. ","GOOG ","512.19","-0.56 (-0.11%) ","159.87B ","3.08M ", 516.13,516.13,507 "Novell, Inc. ","NOVL ","6.84","-0.05 (-0.73%) ","2.39B ","4.49M ", 6.95,6.96,6.76 "Intl Business Machines Corp. ","IBM

Re: Importing Excel/CVS into Database

2007-08-23 Thread Tim Chase
> Tim, in your code: > >filename = 'foo.tab' >for i, line in enumerate(open(filename)): > if i == 0: continue # skip the header row > (fieldname1, fieldname2, fieldname3 ... > ) = line.rstrip('\n').split('\t') > cursor.execute(""" >INSERT INTO app_foo >

Re: Importing Excel/CVS into Database

2007-08-23 Thread robo
**Ben Ford, can you explain a bit more about your code?: for row in reader: obj = MyDjangoModel() obj.__dict__ = row obj.save() Correct my interpretation if it's wrong. If my CSV file has columns "first", "last", "phone", and "email", then MyDjangoModel would contain those 4 fields.

Re: Importing Excel/CVS into Database

2007-08-22 Thread Ben Ford
It worked? Sweet ;-) On 23/08/07, Amirouche <[EMAIL PROTECTED]> wrote: > > > > > On 22 août, 09:51, "Ben Ford" <[EMAIL PROTECTED]> wrote: > > A quick hack that should work would be to create a DictReader object to > read > > the csv with (have a look in the python docs > >

Re: Importing Excel/CVS into Database

2007-08-22 Thread Amirouche
On 22 août, 09:51, "Ben Ford" <[EMAIL PROTECTED]> wrote: > A quick hack that should work would be to create a DictReader object to read > the csv with (have a look in the python docs > here). That's actullay what I did but I didn't know about the

Re: Importing Excel/CVS into Database

2007-08-22 Thread Ben Ford
A quick hack that should work would be to create a DictReader object to read the csv with (have a look in the python docs here). For each row you need to write do: for row in reader: obj = MyDjangoModel() obj.__dict__ = row obj.save() I

Re: Importing Excel/CVS into Database

2007-08-21 Thread Amirouche
On Aug 21, 8:37 pm, robo <[EMAIL PROTECTED]> wrote: > Have any of you guys imported excel/cvs by using Python/Django? I need > to import 1000 products for a shopping site and I'd like to learn the > fastest and easiest way to do so. I already did this, but in another way. 1. I write Models, 2.

Re: Importing Excel/CVS into Database

2007-08-21 Thread Aidas Bendoraitis
Yes, I've done that. The following function read_excel_csv works with Excel CSV files saved on Mac (I can't remember exactly, but it might be that MS Office for Mac OS X saves CSV files using different separators than on Windows). The function reads the rows line by line, parses the cells of each

Re: Importing Excel/CVS into Database

2007-08-21 Thread olivier
> Have any of you guys imported excel/cvs by using Python/Django? I need > to import 1000 products for a shopping site and I'd like to learn the > fastest and easiest way to do so. If you need to load data straight from the Excel, you can use xlrd, which works great.

Re: Importing Excel/CVS into Database

2007-08-21 Thread Tim Chase
> Have any of you guys imported excel/cvs by using > Python/Django? I need to import 1000 products for a shopping > site and I'd like to learn the fastest and easiest way to do > so. I do this day in and day out :) I prefer tab-delimited because it's easy and clean, though Python's built-in

Re: Importing Excel/CVS into Database

2007-08-21 Thread Kirk Strauser
On Tuesday 21 August 2007, robo wrote: > Have any of you guys imported excel/cvs by using Python/Django? Check out "pydoc csv". Python ships with a nice CSV-reader module. -- Kirk Strauser signature.asc Description: This is a digitally signed message part.

Importing Excel/CVS into Database

2007-08-21 Thread robo
Hi, Have any of you guys imported excel/cvs by using Python/Django? I need to import 1000 products for a shopping site and I'd like to learn the fastest and easiest way to do so. Is there any free/shareware programs you guys would recommend? Thanks.