
readmore
This blog is not a political blog, the rest of content is about Python Programming.It is also NOT for Python the Snake
Return a result record of the query
For example:for row in cur.fetchall( ):
- fetchall( ) - return all as a tuple
print "name",row[0], "address",row[1]
2. fetchone( ) - return first row
for row in cur.fetchone( ):
print "............................
3. fetchmany( size) - return row according to size
for row in cur.fetchmany(200)
print "%s | %s |%s" %row
name_last age
------------------------------------------------------------------------------
Putin 51
Lebed 53
Zhirinovsky 57
Yeltsin 72
import sys
# input a original file
inp = open("december.txt","r")
#write to a new file
outp = open("newDecember.txt","w")
#declare global
lines = inp.readlines()
for line in lines:
#find the string
if(line.find("asfgsfhhshas")!=-1):
## print line
#write to a new file
sys.stdout.write(line)
outp.write(line)
inp = open("december.txt","r")
badf = open("badDecember.txt","w")
goodf = open("goodDecember.txt",'w')
lines = inp.readlines()
for line in lines:
if line.find("asfgsfhhshas") != -1:
sys.stdout.write(line)
badf.write(line)
else:
goodf.write(line)
badf.close()
goodf.close()
inp.close()
Database is a structured collection of data that is stored in a computer. A computer program, that manages and queries a database is calles a Database Management System (DBMS). Some thirty years ago, DBMS were available only in the research laboratories of giant companies like IBM. Later on, they began to spread. But they were very expensive. These days, we can found DBMS everywhere. On the web, on our personal computers, in various mobile devices or portables. We can have many different databeses for little or no money that would cost thousands of dollars in the past. We live in interesting times.
There are various database models. The most significant database model is the relational database model (RDBMS). The data is divided into tables. Among these tables we define relations. We all have heard about various database management systems. There are several well known commercial DBMS as well as open source ones.
Commercial RDBMS
| Opensource RDBMS
|
Starting from Python 2.5.x series, an SQLite library is included in the python language. SQLite is a small embeddable library. This means that programmers can integrate the libraty inside their applications. No server is needed to work with SQLite. Therefore SQLite is also called a zero-configuration SQL database engine.
SQLite has the following features.
SQLite supports these data types:
Before we start working with SQLite, we define some important terms. A database query is a search for information from a database. A query is written in SQL language. Structured Query Language (SQL) is a computer language used to create, retrieve, update and delete data from the database. It was developed by the IBM corporation. SQL language has three subsets.
filename means you must replace the text filename with the name of the file including extension that you are using.
C:\Python23 is an example; replace C:\Python23 with the actual drive letter and directory where your Python is installed.
If standard Python file extensions like .py are associated with Python (the default for a standard Windows installation) then you can simply double-click a Python source file in Windows Explorer to run the script. There are 2 problems with this method:
raw_input("Press ENTER to continue...")
Using Command Prompt
The windows command prompt can be accessed via START/RUN/CMD
The phrase "Enter the command ..." means type the command at the prompt and press the Enter key.
C:\Python25 is an example; replace C:\Python25 with the actual drive letter and directory where your Python is installed.