Reading from a Database,readingdatabase,import MySQL
Reading from a Database,readingdatabase,import MySQL
import MySQLdbdb= MySQLdb.connect(host='localhost', user='python-test', passwd='python',db='python-test')cursor = db.cursor()stmt = 'SELECT * from books'cursor.execute(stmt)rows = cursor.fetchall ()for row in rows: print 'Row: ' for col in row : print 'Column: %s' % (col) print 'End of Row'print 'Number of rows returned: %d' % cursor.rowcountcursor.close()db.close()
- Use Pickle to save and read,picklesave,import pickl
- Find a word in shelve file,findshelve,import sys,
- hex literals,literals,print 0x01,
- Reading a binary File,readingbinaryfile,f = open('/m
- Slicing works similar to strings; use the square bracket
- Read a file line by line and check line separator,chec
热门文章:
相关内容
- Use Pickle to save and read,picklesave,import pickl
- Find a word in shelve file,findshelve,import sys,
- hex literals,literals,print 0x01,
- Reading a binary File,readingbinaryfile,f = open('/m
- Slicing works similar to strings; use the square bracket slice operat
- Read a file line by line and check line separator,checkseparator,im
- Looping Over Characters with read Writing the Loop Differently,loop
- Text files: iterating over the lines in the file,iteratinglines,f =
- Reading the entire file at once,readingentire,print '\nRea
- Creating a text file with the writelines() method.,creatingwritelin
评论关闭