<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'reading from csv database' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'reading from csv database' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 22:27:26 -0700</pubDate>
    <lastBuildDate>Sat, 25 May 2013 22:27:26 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>reading from csv database</title>
      <link>http://www.programmersheaven.com/mb/python/177228/177228/reading-from-csv-database/</link>
      <description>Hi,I'm new to python and programming and have been asked to write a script to read lines from a database for including in an html table.As the database runs to about 1000 line I need to split it into about 10-20 sections.How do I link a subject to a line number and then output all lines that occur until the next subject? Do I make the subject the key in a dictionary with the line number the value? I would greatly appreciate some input as I,m finding this very difficult without experienced advise.many thanks&lt;br /&gt;
nevle&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/177228/177228/reading-from-csv-database/</guid>
      <pubDate>Tue, 18 Mar 2003 00:13:32 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: reading from csv database</title>
      <link>http://www.programmersheaven.com/mb/python/177228/177310/re-reading-from-csv-database/#177310</link>
      <description>: Hi,I'm new to python and programming and have been asked to write a script to read lines from a database for including in an html table.As the database runs to about 1000 line I need to split it into about 10-20 sections.How do I link a subject to a line number and then output all lines that occur until the next subject? Do I make the subject the key in a dictionary with the line number the value? I would greatly appreciate some input as I,m finding this very difficult without experienced advise.many thanks&lt;br /&gt;
&lt;br /&gt;
Could you describe the database structure?  How is the data stored?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;em&gt;&lt;span style="color: Blue;"&gt;&lt;span style="color: Red;"&gt;i&lt;/span&gt;nfidel&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/177228/177310/re-reading-from-csv-database/#177310</guid>
      <pubDate>Tue, 18 Mar 2003 07:31:39 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: reading from csv database</title>
      <link>http://www.programmersheaven.com/mb/python/177228/178404/re-reading-from-csv-database/#178404</link>
      <description>: : Hi,I'm new to python and programming and have been asked to write a script to read lines from a database for including in an html table.As the database runs to about 1000 line I need to split it into about 10-20 sections.How do I link a subject to a line number and then output all lines that occur until the next subject? Do I make the subject the key in a dictionary with the line number the value? I would greatly appreciate some input as I,m finding this very difficult without experienced advise.many thanks&lt;br /&gt;
: &lt;br /&gt;
: Could you describe the database structure?  How is the data stored?&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;span style="font-size: large;"&gt;&lt;em&gt;&lt;span style="color: Blue;"&gt;&lt;span style="color: Red;"&gt;i&lt;/span&gt;nfidel&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
: &lt;br /&gt;
:Hi,Thanks for your reply,The data is a pricelist in excel,with columns for decsciption, price,tax, etc(7 items in all) with headings for each item.I can't figure out how to list all the lines from one heading to the next?It must be easy but I cannot see it!  &lt;br /&gt;
&lt;br /&gt;
nevle&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/177228/178404/re-reading-from-csv-database/#178404</guid>
      <pubDate>Mon, 24 Mar 2003 03:33:18 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: reading from csv database</title>
      <link>http://www.programmersheaven.com/mb/python/177228/178482/re-reading-from-csv-database/#178482</link>
      <description>: :Hi,Thanks for your reply,The data is a pricelist in excel,with columns for decsciption, price,tax, etc(7 items in all) with headings for each item.I can't figure out how to list all the lines from one heading to the next?It must be easy but I cannot see it!  &lt;br /&gt;
&lt;br /&gt;
Sorry if I sound dense, but I'm having a hard time picturing what you're trying to do.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;em&gt;&lt;span style="color: Blue;"&gt;&lt;span style="color: Red;"&gt;i&lt;/span&gt;nfidel&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/177228/178482/re-reading-from-csv-database/#178482</guid>
      <pubDate>Mon, 24 Mar 2003 08:45:11 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: reading from csv database</title>
      <link>http://www.programmersheaven.com/mb/python/177228/178570/re-reading-from-csv-database/#178570</link>
      <description>: : :Hi,Thanks for your reply,The data is a pricelist in excel,with columns for decsciption, price,tax, etc(7 items in all) with headings for each item.I can't figure out how to list all the lines from one heading to the next?It must be easy but I cannot see it!  &lt;br /&gt;
: &lt;br /&gt;
: Sorry if I sound dense, but I'm having a hard time picturing what you're trying to do.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
:Hi Infidel,I'm obviously not describing my problem very well so I'll try from a different angle.How do I read specific rows from data in an Excel spreadsheet.I have tried variations of this:&lt;br /&gt;
&lt;br /&gt;
file=open("/home/pricelist.csv","r")&lt;br /&gt;
line=(file.readlines())&lt;br /&gt;
file.close&lt;br /&gt;
rows=len(line)&lt;br /&gt;
list=[]&lt;br /&gt;
print rows&lt;br /&gt;
for count in range(1,rows):&lt;br /&gt;
    myline=line[count]&lt;br /&gt;
    splitline=re.split('","|\n',myline)&lt;br /&gt;
    if splitline[0]=='CD/CDRW/DVD Drive':&lt;br /&gt;
        print myline&lt;br /&gt;
        list.append(count)&lt;br /&gt;
    if splitline[0]=='Computer Cases':&lt;br /&gt;
        print myline&lt;br /&gt;
        list.append(count)&lt;br /&gt;
print list&lt;br /&gt;
Then I need to list all rows between these two headings.Am I doing this right?Sorry I've taken up so much of your time but thanks for your help&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
nevle&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/177228/178570/re-reading-from-csv-database/#178570</guid>
      <pubDate>Mon, 24 Mar 2003 16:21:16 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: reading from csv database</title>
      <link>http://www.programmersheaven.com/mb/python/177228/178656/re-reading-from-csv-database/#178656</link>
      <description>: : : :Hi,Thanks for your reply,The data is a pricelist in excel,with columns for decsciption, price,tax, etc(7 items in all) with headings for each item.I can't figure out how to list all the lines from one heading to the next?It must be easy but I cannot see it!  &lt;br /&gt;
: : &lt;br /&gt;
: : Sorry if I sound dense, but I'm having a hard time picturing what you're trying to do.&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: :Hi Infidel,I'm obviously not describing my problem very well so I'll try from a different angle.How do I read specific rows from data in an Excel spreadsheet.I have tried variations of this:&lt;br /&gt;
: &lt;br /&gt;
: file=open("/home/pricelist.csv","r")&lt;br /&gt;
: line=(file.readlines())&lt;br /&gt;
: file.close&lt;br /&gt;
: rows=len(line)&lt;br /&gt;
: list=[]&lt;br /&gt;
: print rows&lt;br /&gt;
: for count in range(1,rows):&lt;br /&gt;
:     myline=line[count]&lt;br /&gt;
:     splitline=re.split('","|\n',myline)&lt;br /&gt;
:     if splitline[0]=='CD/CDRW/DVD Drive':&lt;br /&gt;
:         print myline&lt;br /&gt;
:         list.append(count)&lt;br /&gt;
:     if splitline[0]=='Computer Cases':&lt;br /&gt;
:         print myline&lt;br /&gt;
:         list.append(count)&lt;br /&gt;
: print list&lt;br /&gt;
: Then I need to list all rows between these two headings.Am I doing this right?Sorry I've taken up so much of your time but thanks for your help&lt;br /&gt;
&lt;br /&gt;
Ah, ok.  I didn't know what CSV files were so I made up a simple on in Excel to see what they look like.  I'm with you now.  Here is my script which reads the contents of a csv file, and prints out all the lines from the one that starts with 'CD/CDRW/DVD Drive' through the one that starts with 'Computer Cases':&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
lines = open("K:\\EXCEL\\Book1.csv","r").read().split("\n"
)
output = False
for line in lines:
    if line.find("CD/CDRW/DVD Drive") == 0:
        output = True
    elif line.find("Computer Cases") == 0:
        print line
        break
    if output: print line
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Notice that you're making things more difficult than they need to be.  Python is quite intelligent in its syntax.  You can iterate through a list without ever using an index.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;&lt;em&gt;&lt;span style="color: Blue;"&gt;&lt;span style="color: Red;"&gt;i&lt;/span&gt;nfidel&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/177228/178656/re-reading-from-csv-database/#178656</guid>
      <pubDate>Tue, 25 Mar 2003 07:57:34 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: reading from csv database</title>
      <link>http://www.programmersheaven.com/mb/python/177228/178764/re-reading-from-csv-database/#178764</link>
      <description>: : : : :Hi,Thanks for your reply,The data is a pricelist in excel,with columns for decsciption, price,tax, etc(7 items in all) with headings for each item.I can't figure out how to list all the lines from one heading to the next?It must be easy but I cannot see it!  &lt;br /&gt;
: : : &lt;br /&gt;
: : : Sorry if I sound dense, but I'm having a hard time picturing what you're trying to do.&lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : :Hi Infidel,I'm obviously not describing my problem very well so I'll try from a different angle.How do I read specific rows from data in an Excel spreadsheet.I have tried variations of this:&lt;br /&gt;
: : &lt;br /&gt;
: : file=open("/home/pricelist.csv","r")&lt;br /&gt;
: : line=(file.readlines())&lt;br /&gt;
: : file.close&lt;br /&gt;
: : rows=len(line)&lt;br /&gt;
: : list=[]&lt;br /&gt;
: : print rows&lt;br /&gt;
: : for count in range(1,rows):&lt;br /&gt;
: :     myline=line[count]&lt;br /&gt;
: :     splitline=re.split('","|\n',myline)&lt;br /&gt;
: :     if splitline[0]=='CD/CDRW/DVD Drive':&lt;br /&gt;
: :         print myline&lt;br /&gt;
: :         list.append(count)&lt;br /&gt;
: :     if splitline[0]=='Computer Cases':&lt;br /&gt;
: :         print myline&lt;br /&gt;
: :         list.append(count)&lt;br /&gt;
: : print list&lt;br /&gt;
: : Then I need to list all rows between these two headings.Am I doing this right?Sorry I've taken up so much of your time but thanks for your help&lt;br /&gt;
: &lt;br /&gt;
: Ah, ok.  I didn't know what CSV files were so I made up a simple on in Excel to see what they look like.  I'm with you now.  Here is my script which reads the contents of a csv file, and prints out all the lines from the one that starts with 'CD/CDRW/DVD Drive' through the one that starts with 'Computer Cases':&lt;br /&gt;
: &lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: lines = open("K:\\EXCEL\\Book1.csv","r").read().split("\n"
)
: output = False
: for line in lines:
:     if line.find("CD/CDRW/DVD Drive") == 0:
:         output = True
:     elif line.find("Computer Cases") == 0:
:         print line
:         break
:     if output: print line
: &lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
: Notice that you're making things more difficult than they need to be.  Python is quite intelligent in its syntax.  You can iterate through a list without ever using an index.&lt;br /&gt;
: &lt;br /&gt;
Hi Infidel,I want to thank you for your patience with me,I would not have thought of that solution.I will not bother you for a while as I try and expand what youhave shown me,I appreciate more than I can put into words people like you who are willing to spend their time helping others come to grips with what can be a daunting challenge.thanks  &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
nevle&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/177228/178764/re-reading-from-csv-database/#178764</guid>
      <pubDate>Wed, 26 Mar 2003 00:57:09 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>