当我尝试使用dumps方法时,我得到了错误:TypeError: Object of type datetime is not JSON serializable。这样可以转换这样的类吗?import jsonfrom types import SimpleNamespace
def __init__(self, name='', date=datetime.datetime.now(), price=0.0
我使用python从数据库表中转储了文本文件中的以下行。,并加载数据库表。将此数据从文件中加载为python中的列表使用ast.literal_eval,但只有在文件中没有datetime对象的情况下才能工作。with open('file.txt') as f:但是,当存在datetime对象时,我会得到以下错误:
ValueError从文件中将行加载到