小编ham*_*nni的帖子

使用 openpyxl 将 python 字典列表写入 xlsx

我尝试使用以下方法将list其写入文件dictsxlsxopenpyxlsx

products= [{'id':46329', 
            'discription':'AD BLeu', 
            'marque':'AZERT',
            'category':'liquid',
            'family': 'ADBLEU', 
            'photos':'D:\\hamzawi\\hamza\\image2py\\46329_1.png'},
            {dict2 ...},
            {dictn...}
           ]
Run Code Online (Sandbox Code Playgroud)
 # creat a workbook
 filena = "produitimage.xlsx"
 workbook = Workbook()
 sheet = workbook.active
 #add headers
 sheet.append(["Product ID", "Product Name", "Marque",
          "Category", "Family", "Photos"])
 for product in products:
    for item in product.items():
        for row, entry in enumerate(item, start=3):
            sheet.cell(row=row, column=1, value=entry)
 #add some images
 images = [item['photos'] for item in products]
 for image in images:
     logo = Image(image)
     #logo.height = 150 …
Run Code Online (Sandbox Code Playgroud)

python image openpyxl

4
推荐指数
1
解决办法
5320
查看次数

是否可以使用 Pydantic BaseModel orm_mode 从 gui 类获取数据

是否可以使用从 Pydantic.BaseModel 继承的模型类通过设置 orm_mode= true 来从 GUI 类获取数据,就像与数据库一起使用一样

from typing import List
from sqlalchemy import Column, Integer, String
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy.ext.declarative import declarative_base
from pydantic import BaseModel, constr

Base = declarative_base()


class CompanyOrm(Base):
    __tablename__ = 'companies'
    id = Column(Integer, primary_key=True, nullable=False)
    public_key = Column(String(20), index=True, nullable=False, unique=True)
    name = Column(String(63), unique=True)
    domains = Column(ARRAY(String(255)))


class CompanyModel(BaseModel):
    id: int
    public_key: constr(max_length=20)
    name: constr(max_length=63)
    domains: List[constr(max_length=255)]

    class Config:
        orm_mode = True
Run Code Online (Sandbox Code Playgroud)

''''如果可以的话我该怎么做?

python pydantic

3
推荐指数
1
解决办法
6404
查看次数

如何处理需要太多参数的函数?

我有一堂课,看起来像这样:

class Product(BaseModel):
    code: str = ...
    discription_one: str = ...
    famille: FamilleProduct
    sou_famille: SouFamileProduct
    parent: ParentProduct
    sou_parent: SouParentProduct
    group: GroupProduct
    sou_group: SouGroupProduct
    reference: Optional[str] = ''
    oem: Optional[str] = ''
    other_code: Optional[str] = ''
    discription_two: Optional[str] = ''
    discription_three: Optional[str] = ''
    remarque: Optional[str] = ''
    marque: Marque
    origine: Country
    unite: UniteProduct
    code_sh: ShCode
    numbre_serie: NumbreSerie
    qr_code: QrProduct
    status: StatusProduct
    product_visible: bool = True
    product_loocked: bool = False
    product_hided: bool = False
    location: LocationProduct
    last_prix_achat: float = 0.00
    pmp_achat: …
Run Code Online (Sandbox Code Playgroud)

python

3
推荐指数
1
解决办法
2747
查看次数

标签 统计

python ×3

image ×1

openpyxl ×1

pydantic ×1