Python:生成一个我可以在MySQL中使用的日期时间字符串

Python:生成一个我可以在MySQL中使用的日期时间字符串,python,mysql,time,scrapy,Python,Mysql,Time,Scrapy,如何做到这一点: 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) 这将导致一个错误: 打印时间.strftime(r“%d.%m.%Y%H:%m:%S”,time.localtime() exceptions.AttributeError:“内置函数”或“方法”对

如何做到这一点:

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)
这将导致一个错误:

打印时间.strftime(r“%d.%m.%Y%H:%m:%S”,time.localtime() exceptions.AttributeError:“内置函数”或“方法”对象没有属性“strftime”

我发现了大量的信息——但似乎我要么需要将其直接放入sql查询,要么需要导入其他内容?
我希望先将时间以字符串形式传递给我的对象。

您正在从
time
模块导入
time()
函数。相反,您需要导入模块。替换:

from time import time
与:

演示:

>>从时间导入时间
>>>当前时间=time.strftime(r“%d.%m.%Y%H:%m:%S”,time.localtime()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
AttributeError:“内置函数”或“方法”对象没有属性“strftime”
>>>导入时间
>>>当前时间=time.strftime(r“%d.%m.%Y%H:%m:%S”,time.localtime()
>>>当前时间
'13.05.2015 15:26:45'

作为补充说明,另一个将时间戳附加到数据库中的已删除项的选项是使用MySQL函数,并在将项插入管道中的数据库时调用它。

我知道
NOW()
但想学习Python方面;)非常感谢,这很有效。
import time
>>> 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'