pyhton...

Pages: 12

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



Last edited on
Sample program for SQL



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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()

Topic archived. No new replies allowed.
Pages: 12