python (63):dataclasses 简单示例

dataclasses 简单示例:

import transformers
from dataclasses import dataclass,field
import argparse

@dataclass
class Person():
    age: int = field(default=10)
    Name: str = field(default="Tom")
    high: int = field(
        default=185,
        metadata={
            "help": "people high."
        },
    )
    boy: bool = False

if __name__ == "__main__":
    parser = transformers.HfArgumentParser(
        (Person)
    )
    (
        PerSon,
    ) = parser.parse_args_into_dataclasses()
    print(PerSon.boy)

>>>python file.py

>>>False

>>>python file.py --boy

>>>True

 

posted on 2024-04-15 22:41  细雨微光  阅读(73)  评论(0编辑  收藏  举报