小编Asy*_*llz的帖子

alpine:3.14 docker libtls.so.20 conflict

So I am running into an error with the latest docker build from alpine. alpine:3.14.0 was released about a day ago and was trying to install libressl and libressl-dev and both seem to fail with the error below. My work around at the moment was to build using the alpine:3.12.0 as 3.12.0 seems to not have libretls installed. Although I would like to know how to fix this. I tried to remove libretls but that didn't work (error also below). …

docker libressl alpine-linux

8
推荐指数
1
解决办法
2250
查看次数

将 pydantic 与 xml 一起使用

我正在开发一个使用大量 xml 的项目,并且想使用 pydantic 来建模对象。在本例中,我简化了 xml,但包含了一个示例对象。

<ns:SomeType name="NameType" shortDescription="some data">
  <ns:Bar
    thingOne="alpha"
    thingTwo="beta"
    thingThree="foobar"/>
</ns:SomeType>
Run Code Online (Sandbox Code Playgroud)

代码

from pydantic import BaseModel
from typing import Optional, List
from xml.etree import ElementTree as ET


class Bar(BaseModel):
  thing_one: str
  thing_two: str
  thing_three: str


class SomeType(BaseModel):
  name: str
  short_description: str
  bar: Optional[Bar]


def main():
  with open("path/to/file.xml") as fp:
    source = fp.read()
  root = ET.fromstring(source)
  some_type_list = []
  for child in root:
    st = SomeType(
      name=child.attrib["name"],
      short_description=child.attrib["shortDescription"],
    )
    for sub in child:
      st.bar = Bar(
        thing_one=sub.attrib["thingOne"], …
Run Code Online (Sandbox Code Playgroud)

python xml pydantic

6
推荐指数
1
解决办法
5263
查看次数

标签 统计

alpine-linux ×1

docker ×1

libressl ×1

pydantic ×1

python ×1

xml ×1