For programming object oriented, it would also have to support inheritence and polymorphy
Inheritance and polymorphysm is not a requirement for OOP. OOP is just composing your programs of objects that interchange messages. Object = state + operations on the state, so the essence of OOP is encapsulation, just as Seraphimsan said.
Structural programming = global mutable state
Object oriented programming = mutable state encapsulated in objects
Functional programming = no mutable state at all
Now by the controversial theorem that mutable state is evil you get:
FP > OOP > SP
import MySQLdb
import MySQLdb.cursors
def get_column_name( data, prompt, names ) :
value=-1
while value == -1:
idx = 1
for col in data :
print str(idx) + ": " + col
names.append( col )
idx = idx + 1
value = int( raw_input(prompt) )
if value < 1 or value >= idx :
value = -1
return value
conn = MySQLdb.Connect(
host='localhost', user='python-test',
passwd='python', db='python-test')
cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor.execute("SELECT * FROM books")
data = cursor.fetchone()
names = []
old_value = get_column_name( data, "Which column do you want to change records for? ", names )
names = []
new_value = get_column_name( data, "Which column do you want to change records to? ", names )
old_val = raw_input("What value do you want to change for " + names[old_value-1] + ": ")
new_val = raw_input("What value do you want to change to for " + names[new_value-1] + ": ")
stmt = "UPDATE books SET " + names[new_value-1] + " = '"+ new_val + "' WHERE " + names[old_value-1] + " = '" + old_val + "'"
print stmt
cursor.execute(stmt)
print "Rows affected: " + str(cursor.rowcount)
cursor.close()
conn.commit()
conn.close()