for i in map(abs, (-1,2): print(i)
list(map(abs, (-1, 2))
b = { k : k for k in a.keys()}
@contextmanager
def _new_connection(self):
conn = None
try:
conn = sqlite3.connect(self.db_file)
conn.cursor().execute(CREATE_TABLE % 'tasks (task_id, cc_id, expired)')
conn.cursor().execute(CREATE_TABLE % 'task_actions (task_id, action)')
conn.commit()
yield conn
except sqlite3.DatabaseError as e:
pass
finally:
if conn:
conn.close()
def __init__(self):
while True:
''' creates a connection at the initialization moment
and also a cursor used later '''
try:
# creates a connection
self.conn = MySQLdb.connect( host = self.dbhost,
port = self.dbport,
user = self.dbuser,
passwd = self.dbpass
)
self.cursor = self.conn.cursor()
break
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
time.sleep(5)
defaultdict from collections
setdefault
try:
d[key] += x
except IndexError:
d[key] = default