Use Python 3 syntax

This commit is contained in:
Éric Araujo 2011-10-06 13:26:09 +02:00
parent d032c67418
commit 33c24a46d3
1 changed files with 17 additions and 16 deletions

View File

@ -366,29 +366,29 @@ Example 1: NumPy Arrays
return "barray(%s)" % ndarray.__str__(self)
def __and2__(self, other):
return (self & other)
return self & other
def __or2__(self, other):
return (self & other)
return self & other
def __not__(self):
return (self == 0)
return self == 0
def barray(*args, **kwds):
return array(*args, **kwds).view(type = BArray)
return array(*args, **kwds).view(type=BArray)
a0 = barray([0, 1, 2, 4])
a1 = barray([1, 2, 3, 4])
a2 = barray([5, 6, 3, 4])
a3 = barray([5, 1, 2, 4])
print "a0:", a0
print "a1:", a1
print "a2:", a2
print "a3:", a3
print "not a0:", not a0
print "a0 == a1 and a2 == a3:", a0 == a1 and a2 == a3
print "a0 == a1 or a2 == a3:", a0 == a1 or a2 == a3
print("a0:", a0)
print("a1:", a1)
print("a2:", a2)
print("a3:", a3)
print("not a0:", not a0)
print("a0 == a1 and a2 == a3:", a0 == a1 and a2 == a3)
print("a0 == a1 or a2 == a3:", a0 == a1 or a2 == a3)
Example 1 Output
----------------
@ -417,7 +417,7 @@ Example 2: Database Queries
#
#-----------------------------------------------------------------
class SQLNode(object):
class SQLNode:
def __and2__(self, other):
return SQLBinop("and", self, other)
@ -473,7 +473,7 @@ Example 2: Database Queries
return self
def __sql__(self):
result = "SELECT %s" % ", ".join([sql(target) for target in self.targets])
result = "SELECT %s" % ", ".join(sql(target) for target in self.targets)
if self.where_clause:
result = "%s WHERE %s" % (result, sql(self.where_clause))
return result
@ -491,9 +491,10 @@ Example 2: Database Queries
def select(*targets):
return SQLSelect(targets)
#--------------------------------------------------------------------------------
::
dishes = Table("dishes")
customers = Table("customers")
orders = Table("orders")
@ -502,8 +503,8 @@ Example 2: Database Queries
customers.cust_id == orders.cust_id and orders.dish_id == dishes.dish_id
and dishes.name == "Spam, Eggs, Sausages and Spam")
print repr(query)
print sql(query)
print(repr(query))
print(sql(query))
Example 2 Output
----------------