Prev: Embedding, subinterpreters and dynamic types
Next: how to make portable distribution of python 2.6?
From: Praveen on 13 Aug 2010 12:46 I have a text file in this format PRA 1:13 2:20 3:5 SRA 1:45 2:75 3:9 TRA 1:2 2:65 3:45 pattern is- Book Chapter:Verses now i have my DB schema like this book_id chapter_id versed_id 1 1 13 1 2 20 1 3 5 2 1 45 2 2 75 2 3 9 3 1 2 3 2 65 3 3 45 I want to write a pyhton script which read the text file and dump to DB could any one give me suggestion
From: MRAB on 13 Aug 2010 14:09 Praveen wrote: > I have a text file in this format > PRA 1:13 2:20 3:5 > SRA 1:45 2:75 3:9 > TRA 1:2 2:65 3:45 > > pattern is- Book Chapter:Verses > > now i have my DB schema like this > book_id chapter_id versed_id > 1 1 13 > 1 2 20 > 1 3 5 > 2 1 45 > 2 2 75 > 2 3 9 > 3 1 2 > 3 2 65 > 3 3 45 > > I want to write a pyhton script which read the text file and dump to > DB > > could any one give me suggestion Read through the file a line at a time. For the first line the book_id is 1, for the second it's 2, etc. Split each line on whitespace, and then for all but the first entry (which is a name?) split on the colon to get the chapter_id and versed_id. Insert each tuple of (book_id, chapter_id, versed_id) into the DB. You haven't said what type of DB it is, so I can't help you there. Just read the documentation.
|
Pages: 1 Prev: Embedding, subinterpreters and dynamic types Next: how to make portable distribution of python 2.6? |