[Tutor] make a sqlite3 database from an ordinary text file

Manprit Singh manpritsinghece at gmail.com
Sun Jun 19 14:37:42 EDT 2022


Dear sir ,

One more query ....
How can i use column name in text file as colum names in sqlite3 database .
I tried using python but failed.

Can you put some light over it ?
Regards
Manprit Singh

On Sun, 19 Jun, 2022, 23:36 Alan Gauld via Tutor, <tutor at python.org> wrote:

> On 19/06/2022 18:11, Manprit Singh wrote:
>
> > cur.execute("create table workdata(Time INT, Pieces INT)")
>
> This will fail the second time it runs. You should check
> if the table already exists and either drop it or use
> the existing table.
>
> However, I rarely create tables from Python, it's generally
> easier to create a sql file and run that directly using
> the sqlite interpreter. You only need Python if the format
> of the table has to be deduced from the data. and that then
> leads to all sorts of follow-on issues over accessing names
> of columns etc.
>
> Once you have the table you can then use Python to load
> the data, although in your case you could do that directly
> from SQL too since it looks like a tab separated file.
>
> As always use the most appropriate tool. If you can do it
> directly in SQL there is no point in wrapping it in
> Python. That just adds complexity and slows things
> down.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list