Code
from pydantic import BaseModel
class InventoryItem(BaseModel):
str
item_name: float
price: = InventoryItem(item_name="Banana", price=10)
my_item my_item
InventoryItem(item_name='Banana', price=10.0)
DSAN 5500: Data Structures, Objects, and Algorithms in Python
from pydantic import BaseModel
class InventoryItem(BaseModel):
str
item_name: float
price: = InventoryItem(item_name="Banana", price=10)
my_item my_item
InventoryItem(item_name='Banana', price=10.0)
= InventoryItem(item_name="Banana", price="100 dollar") invalid_item
ValidationError: 1 validation error for InventoryItem
price
Input should be a valid number, unable to parse string as a number [type=float_parsing, input_value='100 dollar', input_type=str]
For further information visit https://errors.pydantic.dev/2.6/v/float_parsing
from pydantic import BaseModel, EmailStr, PositiveInt
class Employee(BaseModel):
str
name:
email: EmailStr
age: PositiveInt= Employee(
invalid_employee ="Jeef",
name="fakeemail!!!",
email=50
age )
ValidationError: 1 validation error for Employee
email
value is not a valid email address: The email address is not valid. It must have exactly one @-sign. [type=value_error, input_value='fakeemail!!!', input_type=str]
= Employee(
invalid_employee2 ="Jeeferson",
name="valid@email.com",
email=-3
age )
ValidationError: 1 validation error for Employee
age
Input should be greater than 0 [type=greater_than, input_value=-3, input_type=int]
For further information visit https://errors.pydantic.dev/2.6/v/greater_than
Team
objectInventoryItem
object for each row)LogarithmicHashTable
key
and value
separately, or together?tuple
s or InventoryItem
s?InventoryItem
s: What type(s) for item_name
? What type(s) for price
? 😵txt
, epub
(can contain images), pdf
(sometimes text is embedded, sometimes not), images of scans, audiobooks