Zitat von Morg
Beitrag anzeigen
Code:
[smarthome@SmartHomeNG ~]$ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.fromisoformat("2020-05-23")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'datetime.datetime' has no attribute 'fromisoformat'
>>>
Ich habe mit mal die zur Verfügung stehenden Attribute anzeigen lassen:
Code:
>>> print(dir(datetime)) ['__add__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex_ _', '__repr__', '__rsub__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', 'astimezone', 'c ombine', 'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isowee kday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strpt ime', 'time', 'timestamp', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'ut cnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']
Edit2:
Ich glaube, das Attribut "fromisoformat" ist erst mit Python 3.7 eingeführt worden.
Mein ProduktivRPI läuft noch mit 3.5.3.
Edit 3:
Die Lösung: Ich habe die "fromisoformat" durch ein anderes Attribut erstetzt.
Code:
import dateutil.parser
datestring = dateutil.parser.isoparse(value).strftime("%Y%m%d%w%H%M%S")


Einen Kommentar schreiben: