2008-04-14 08:13:07 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
Test if the arguments object can be used with both positional and keyword
|
|
|
|
arguments.
|
|
|
|
"""
|
|
|
|
|
|
|
|
class O(object):
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwds):
|
|
|
|
self.args = args
|
|
|
|
self.kwds = kwds
|
|
|
|
|
|
|
|
def __getitem__(self, k):
|
|
|
|
if isinstance(k, int):
|
|
|
|
return self.args[k]
|
|
|
|
else:
|
|
|
|
return self.kwds[k]
|
|
|
|
|
|
|
|
o = O('R%', second='S%')
|
|
|
|
|
2017-12-04 05:47:19 +03:00
|
|
|
print(o[0])
|
|
|
|
print(o['second'])
|
2008-04-14 08:13:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
import psycopg2 as dbapi
|
|
|
|
|
|
|
|
|
|
|
|
conn = dbapi.connect(database='test')
|
2017-12-02 08:37:49 +03:00
|
|
|
|
|
|
|
|
2008-04-14 08:13:07 +04:00
|
|
|
|
|
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute("""
|
|
|
|
|
|
|
|
SELECT * FROM location_pretty
|
|
|
|
WHERE keyname LIKE %s OR keyname LIKE %(second)s
|
|
|
|
|
|
|
|
""", (o,))
|
|
|
|
|
|
|
|
for row in cursor:
|
2017-12-04 05:47:19 +03:00
|
|
|
print(row)
|