How to do this:
from time import time
import datetime
current_time = time.strftime(r"%d.%m.%Y %H:%M:%S", time.localtime())
l.add_value('time', current_time)
this will end up in an error:
print time.strftime(r"%d.%m.%Y %H:%M:%S", time.localtime()) exceptions.AttributeError: 'builtin_function_or_method' object has no attribute 'strftime'
I found plenty of information - but it seems as if I either need to put it directly into an sql query or import anything else? I'd like to have the time in a string first to pass it to my object.
You are importing a time()
function from the time
module. Instead, you need to import the module. Replace:
from time import time
with:
import time
Demo:
>>> from time import time
>>> current_time = time.strftime(r"%d.%m.%Y %H:%M:%S", time.localtime())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute 'strftime'
>>> import time
>>> current_time = time.strftime(r"%d.%m.%Y %H:%M:%S", time.localtime())
>>> current_time
'13.05.2015 15:26:45'
As a side note, another option to have a time stamp attached to a scraped item in the database, would be to use NOW()
MySQL function and call it while inserting an item into the database in the pipeline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With