简体   繁体   中英

How do I define a datetime field in a python dataclass?

trying to get the syntax of the Python 3.7 new dataclass right.

if I want to include a datetime value in my dataclass,

import datetime
from dataclasses import dataclass

@dataclass
class MyExampleWithDateTime:
    mystring: str
    myint: int
    mydatetime: ???

What should I write for ??? for a datetime field?

Like this:

@dataclass
class MyExampleWithDateTime:
    mystring: str
    myint: int
    mydatetime: datetime.datetime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM