Re: importing csv file into sqlite

2008-12-19 Thread John Machin
On Dec 18, 5:17 pm, "James Mills" wrote: > > def readCSV(file): >   if type(file) == str: Stiff cheese if the file path is a unicode object, eh? >      fd = open(file, "rU") >   else: >      fd = file > -- http://mail.python.org/mailman/listinfo/python-list

Re: importing csv file into sqlite

2008-12-19 Thread John Machin
On Dec 19, 11:17 pm, klia wrote: [ancient screed snipped] > > hey guys > i took all of your suggestion but my goal ain't yet achieved :-(( > these are the codes after changes, john i couldn't really catch what do you > mean by renaming input, is it just normal renaming. Somebody else told you n

Re: importing csv file into sqlite

2008-12-19 Thread Peter Otten
klia wrote: > > > John Machin wrote: >> >> On Dec 18, 6:20 pm, klia wrote: >>> klia wrote: >>> >>> > hey guys, i have a hug .csv file which i need to insert it into sqlite >>> > database using python. >>> > my csv data looks like this >>> > Birthday2,12/5/2008,HTC,this is my birthday >>> > Sea

Re: importing csv file into sqlite

2008-12-19 Thread klia
nn.cursor() curse.execute('CREATE TABLE photos (Name VARCHAR(100) PRIMARY KEY, Date INTEGER, Make VARCHAR(50), Tag VARCHAR(100))') for row in input: curse.execute('INSERT INTO photos VALUES (?,?,?,?)', '*row') curse.commit() this time i got this error was

Re: importing csv file into sqlite

2008-12-19 Thread James Mills
On Fri, Dec 19, 2008 at 8:32 PM, Peter Otten <__pete...@web.de> wrote: > James Mills wrote: > >> values = ",".join(["\"%s\"" % x for x in line]) >> print "INSERT INTO %s %s VALUES (%s);" % (table, fields, values) > > http://xkcd.com/327/ It's a tool! Not one meant to be used publicly from untruste

Re: importing csv file into sqlite

2008-12-19 Thread Peter Otten
James Mills wrote: > values = ",".join(["\"%s\"" % x for x in line]) > print "INSERT INTO %s %s VALUES (%s);" % (table, fields, values) http://xkcd.com/327/ -- http://mail.python.org/mailman/listinfo/python-list

Re: importing csv file into sqlite

2008-12-18 Thread James Mills
On Fri, Dec 19, 2008 at 10:11 AM, Gabriel Genellina wrote: > But your code does *exactly* that, it reads the whole file in memory: > >> def mkBuffer(fd): >> buffer = StringIO() >> buffer.write(fd.read()) >> ... > > That mkBuffer function has no useful purpose IMHO, just remove it. It was a mis

Re: importing csv file into sqlite

2008-12-18 Thread Gabriel Genellina
En Thu, 18 Dec 2008 04:17:47 -0200, James Mills escribió: How big ? When size is important in data processing, you should _never_ try to load it all up at once. Use filters... But your code does *exactly* that, it reads the whole file in memory: def mkBuffer(fd): buffer = StringIO() buf

Re: importing csv file into sqlite

2008-12-18 Thread John Machin
On Dec 18, 6:20 pm, klia wrote: > klia wrote: > > > hey guys, i have a hug .csv file which i need to insert it into sqlite > > database using python. > > my csv data looks like this > > Birthday2,12/5/2008,HTC,this is my birthday > > Sea,12/3/2008,kodak,sea > > birthday4,14/3/2009,samsung,birthday

Re: importing csv file into sqlite

2008-12-18 Thread Peter Otten
Chris Rebert wrote: >> klia wrote: >> for item in input: >>curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item) > I believe you need to change 'item' to '*item' to expand the list in > the call so that the function gets 4 additional args rather than 1 > additional arg that happens t

Re: importing csv file into sqlite

2008-12-18 Thread James Mills
@klia: You could have had this done hours ago had you taken my suggestion, used my tool and just piped it into sqlite3 on the command line. --JamesMills -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list

Re: importing csv file into sqlite

2008-12-18 Thread Chris Rebert
On Wed, Dec 17, 2008 at 11:20 PM, klia wrote: > klia wrote: >> >> hey guys, i have a hug .csv file which i need to insert it into sqlite >> database using python. >> my csv data looks like this >> Birthday2,12/5/2008,HTC,this is my birthday >> Sea,12/3/2008,kodak,sea >> birthday4,14/3/2009,samsung

Re: importing csv file into sqlite

2008-12-17 Thread klia
x27;) for item in input: curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item) curse.commit() -- View this message in context: http://www.nabble.com/importing-csv-file-into-sqlite-tp21067453p21068111.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: importing csv file into sqlite

2008-12-17 Thread James Mills
On Thu, Dec 18, 2008 at 3:58 PM, klia wrote: > hey guys, i have a hug .csv file which i need to insert it into sqlite > database using python. > my csv data looks like this > Birthday2,12/5/2008,HTC,this is my birthday > Sea,12/3/2008,kodak,sea > birthday4,14/3/2009,samsung,birthday > love,17/4/20

Re: importing csv file into sqlite

2008-12-17 Thread Chris Rebert
On Wed, Dec 17, 2008 at 9:58 PM, klia wrote: > > hey guys, i have a hug .csv file which i need to insert it into sqlite > database using python. > my csv data looks like this > Birthday2,12/5/2008,HTC,this is my birthday > Sea,12/3/2008,kodak,sea > birthday4,14/3/2009,samsung,birthday > love,17/4/

importing csv file into sqlite

2008-12-17 Thread klia
codes. thanks in advance -- View this message in context: http://www.nabble.com/importing-csv-file-into-sqlite-tp21067453p21067453.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list