[Python] How to manipulate a model (Pydantic) which just is defined at runtime

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have a situation like this: I know there will be a Person object model. But I haven't know it's attribute yet, until run time. a Person object will be defined and write into a Python file in project directory. Another option is at runtime a yml or json file will be created to describe that Person object.

    But I also have to use that Person oject in another function when pre-define function in workflow. this function will be invoked later after Person is defined

    for example:

    def my_func(person: Person): # But this Person isn't defined.
    print(person)


    I'm not sure if I can define a Person then overwrite it later. As I think Python already read that Person object and save into memory then there will be a confict.

    Thank you.

    Continue reading...

Compartilhe esta Página