pymssql (python module) losing item when fetching data
Question: I have a database named "sina2013",and the columus is Title,Content Now I want
to use pymssql module to get the data.At the same time ,using the Title as the
filename of a txt file,the Content as the content of the txt file. The strange
thing is the number of files is less than the items in database. where is the
error? the code i have tried is:

    
    
    import pymssql
    conn = pymssql.connect(...)  
    cur = conn.cursor()
    cur.execute('SELECT Title,Content FROM sina2013')
    count=len(cur.fetchall()) #Will return the right number :5913
    for Title,Content in cur:
        filename=file(str(Title)+r'.txt',r'w')
        filename.write(Content )
        filename.close()
    cur.close()
    

The number of txt file is less than it should be. what is the reason?


Answer: Perhaps changing your for loop into this:

    
    
    # cursor fetchall() method returns all rows from a query
    for Title,Content in cur.fetchall():  
    

... will fix the issue?

