Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pydantic model from dataclass

from datetime import datetime
from pydantic.dataclasses import dataclass


@dataclass
class User:
    id: int
    name: str = 'John Doe'
    signup_ts: datetime = None


user = User(id='42', signup_ts='2032-06-21T12:00')
print(user)
#> User(id=42, name='John Doe', signup_ts=datetime.datetime(2032, 6, 21, 12, 0))
Comment

PREVIOUS NEXT
Code Example
Python :: genisim 4.0 words 
Python :: preallocate numpy array 
Python :: loop regex 
Python :: browser environment: 
Python :: how to aggregate and add new column 
Python :: heatmap colorbar label 
Python :: long armstrong numbers 
Python :: how do i access individual elements of matrix in python? 
Python :: how to add start menu in python 
Python :: Flask select which form to POST by button click 
Python :: How to solve import errors while trying to deploy Flask using WSGI on Apache2 
Python :: pandas combine bool columns 
Python :: Retry function for sending data 
Python :: python complement operator 
Python :: replace string in dictionary python 
Python :: difflib get close matches 
Python :: word cloud mape python 
Python :: Lambda expressions using f-string 
Python :: ret, img_frame = cap.read() 
Python :: numpy mask without losing shape 
Python :: how to add illegal characters to paths python 
Python :: how to split string into list conditionally+python 
Python :: REMOVE ALL ROWS FROM DATFRAME WGICH HAS DATA OLDER THAN 3 MONTHS PANDAS 
Python :: Three-dimensional Contour Plots 
Python :: Shelve Data Storage 
Python :: orm odoo 
Python :: Print all day-dates between two dates [duplicate] 
Python :: r Return each result with an index 
Python :: clase describe algo 
Python :: python check if class has any methods 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =