TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #397 · 12 ное.

Использование Pydantic сегодня стало нормой, и это правильно. Но иногда на ревью вижу, что используют его не всегда корректно. Например, метод BaseModel.model_dump() по умолчанию не преобразует стандартные типы, такие как datetime, UUID или Decimal, в простой сериализуемый для JSON вид. Тогда пишут кастмоный сериализатор для этих типов чтобы функция json.dump() не падала с ошибкой. import uuid from datetime import datetime from decimal import Decimal from uuid import UUID from pydantic import BaseModel class MyModel(BaseModel): id: UUID date: datetime value: Decimal obj = MyModel( id=uuid.uuid4(), date=datetime.now(), value='1.23' ) print(obj.model_dump()) # не подходит для json.dump # { # 'id': UUID('4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1'), # 'date': datetime.datetime(2025, 12, 12, 12, 12, 12, 111111), # 'value': Decimal('1.23') # } # добавляем свой кастомный сериализатор json.dumps(obj.model_dump(), cls=MySerializer) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2025-12-12T12:12:12.111111', # 'value': '1.23' # } В данном случае класс MySerializer обрабатывает datetime, UUID и Decimal. Например так: class MySerializer(json.JSONEncoder): def default(self, o): if isinstance(o, Decimal): return str(o) elif isinstance(o, datetime): return o.isoformat() elif isinstance(o, UUID): return str(o) return super().default(o) Специально для тех, кто всё еще так делает - в этом нет необходимости! Pydantic может это сделать сам, просто нужно добавить параметр mode="json". json.dumps(obj.model_dump(mode="json")) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2012-12-12T12:12:12.111111', # 'value': '1.23' # } #pydantic#libs

Резултати

Пронајдени 1 слични објави

Пребарај: #startupethiopia

当前筛选 #startupethiopia清除筛选

🌟 FROM ADDIS TO SILICON VALLEY: YOUNG ETHIOPIANS BUILDING THE FUTURE! የአዲስ አበባ ወደ ሲሊኮን ቫሊ፡ የኢትዮጵያ ወጣቶች ወደፊቱን እየገነቡ ነው! Your country is not your obstacle - it's your SUPERPOWER! 💪 ሀገርህ መሰናክል አይደለም - ሱፐር ኃይልህ ነው! 🏆 REAL SUCCESS STORIES: 💰BETHLEHEM TILAHUN ALEMU | ብርሀን ጥላሁን ዓለሙ • Founded soleRebels (footwear company) at 25 • $10M+ revenue, exports to 50+ countries • Made from recycled tires + traditional weaving • Featured in Forbes, Times Magazine • "I turned our grandmother's craft into global brand!" 🎵TEDDY AFRO & MUSIC EMPIRE | ቴዎድሮስ ካሳሁን • Albums sold 2M+ copies worldwide • Concert revenues $500K+ per show • African music ambassador to the world • Started from Addis Ababa streets 🌱AGRITECH REVOLUTION: • 2030 Vision: Digital farming apps • EthioSIS: Soil mapping technology (government project) • Young farmers earning 300% more using smartphones • Export potential: $2B+ organic coffee market 👩‍💼WOMEN ENTREPRENEURS: • Maya Haile-Mariam: Tech startup $5M valuation • Selamawit Chekol: Fashion brand expanding to USA • Martha Tilahun: Food processing empire 💡YOUR ADVANTAGES AS ETHIOPIAN: ✅ Ancient culture = unique design aesthetics ✅ Coffee heritage = premium brand story ✅ 13-month calendar = exclusive time management apps ✅ Multilingual (80+ languages) = translation services ✅ High altitude = athletic training programs ✅ History (3000+ years) = educational content gold mine 🚀START TOMORROW - 3 SIMPLE STEPS: 📱 STEP 1: DIGITAL PRESENCE • Create Instagram/TikTok showcasing Ethiopian culture • Use trending hashtags: #EthiopianTradition#AfricanInnovation • Post daily content in English + Amharic 💰 STEP 2: MONETIZE YOUR KNOWLEDGE • Teach Amharic online (Italki, Preply): $15-25/hour • Sell handmade crafts on Etsy: $20-200+ per item • Create YouTube cooking channel: Ethiopian cuisine going viral! 🌍 STEP 3: THINK GLOBAL • Partner with diaspora communities (2M+ Ethiopians worldwide) • Export coffee/spices through e-commerce • Offer virtual Ethiopian cultural experiences 📞RESOURCES TO START: • IceAddis: Startup incubator in Addis Ababa • Ethiopia Commodity Exchange: Connect with coffee buyers • Women in Tech Ethiopia: Female entrepreneurs network • TechnoServe: Business development programs 💎GOLDEN RULE: "Every problem in Ethiopia = business opportunity for smart youth!" 🔥MOTIVATIONAL CLOSE: Your ancestors built Lalibela without cranes. You can build digital empires with just a smartphone! The world needs what Ethiopia has. Your job is to package it beautifully and sell it globally! 🌍✨ የአባቶችህ ላሊበላን ክሬን ሳይጠቀሙ ገነቡት። አንተ ስማርትፎን ብቻ ተጠቅመህ ዲጂታል ግዛቶችን መገንባት ትችላለህ! ✨ Expert-reviewed content | Verified by Ethiopian business & tech specialists #EthiopianEntrepreneurs#StartupEthiopia#DigitalEthiopia#AfricanInnovation#ኢትዮጵያ#BusinessSuccess🇪🇹💰🚀