Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python dict to dataclass

from dataclasses import dataclass
from dacite import from_dict

@dataclass
class User:
    name: str
    age: int
    is_active: bool

data = {
    'name': 'john',
    'age': 30,
    'is_active': True,
}

user = from_dict(data_class=User, data=data)

assert user == User(name='john', age=30, is_active=True)
Comment

PREVIOUS NEXT
Code Example
Python :: pandas index between time 
Python :: pandas make new dataframe 
Python :: python list splicing 
Python :: create dataframe from two variables 
Python :: how to display csv in pandas 
Python :: python get file name 
Python :: python random list of integers without repetition 
Python :: python scraping 
Python :: flask setup 
Python :: strip first occurence of substring python 
Python :: concatenate int to string python 
Python :: push to pypi 
Python :: get random float in range python 
Python :: socket io python 
Python :: selenium firefox webdriver 
Python :: convert 1 to "one" python 
Python :: python delete value from dictionary 
Python :: python socket recv set timeout 
Python :: python relative file path doesnt work 
Python :: del all variables python 
Python :: python xml to csv 
Python :: WebDriverWait 
Python :: selenium if statement python 
Python :: 3d array python numpy 
Python :: random torch tensor 
Python :: current date and time into timestamp 
Python :: how to create a virtual environment in anaconda 
Python :: gematria python 
Python :: python make an object hashable 
Python :: buscar valor aleatorio de una lista python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =