Reputation: 2686
for k,v in account.items():
try:
connection.execute('''
INSERT INTO my_acct
(acct_name, acct_username, acct_password, created_date, category_id)
VALUES (?,?,?,?,?) ''', (k, v[0], v[1] , datetime('now'), 1))
print('\nINSERTED!!!\n')
except:
print('Error Occurred inserting')
When I run, it outputs the except:
block instructions
I took off the try: except: and the datetime('now') is throwing this error:
VALUES (?,?,?,?,?) ''', (k, v[0], v[1] , datetime('now'), 1))
NameError: name 'datetime' is not defined
What am I doing wrong here?
Upvotes: 0
Views: 19
Reputation: 11916
You need to do datetime.now()
, instead of datetime('now')
. But please make sure to import it first.
Example:
from datetime import datetime
print datetime.now()
Upvotes: 2