How To Use: "@dataclass" In Python (Tutorial 2023)

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024

Комментарии • 34

  • @thepackbot
    @thepackbot Год назад +6

    That tidbit about "variables with default values must come after the ones without them", just explained a big problem I was having. Thank you!

  • @FrocketGaming
    @FrocketGaming 6 месяцев назад +1

    Thanks for this. As I was watching and working on a selenium web scraping script I realized I could make a config dataclass to store all the css_selectors / xpaths I need for this script!

  • @djtomoy
    @djtomoy День назад

    5:44 nice 😎

  • @velicihanates
    @velicihanates Год назад +17

    You could have used two asterix operators to insert json in your person class
    'bob = Person(**json)'

    • @Indently
      @Indently  Год назад +7

      Only if your dataclass fits PERFECTLY the data from the JSON, otherwise it will throw an error.

    • @velicihanates
      @velicihanates Год назад

      @@Indently thanks for telling, I really enjoy your python tutorials!

    • @thepackbot
      @thepackbot Год назад

      that's called unpacking.

  • @pankuang-q1k
    @pankuang-q1k 8 месяцев назад

    your explaination is very helpful for understanding the question 'why we need to do that ', and i like your explaination for reading a json file to an object. Thank you very much for this good video.

  • @chromery
    @chromery Год назад

    Great video as always! Have you by any chance made a video about Pydantic (couldn't find it), or are you maybe planning to?

  • @kostasmessinis
    @kostasmessinis 9 месяцев назад +1

    good

  • @davidl3383
    @davidl3383 Год назад +4

    Thank you. Very clear like your udemy couse ;)

  • @developer_anonymous
    @developer_anonymous Год назад +7

    'banana.calories = 69, i mean, 60' 😂

  • @mecrayavcin
    @mecrayavcin 4 месяца назад

    Nice video

  • @MrGeordiejon
    @MrGeordiejon Месяц назад

    bob = Person(**json)
    print(bob)
    >>> Person(name='Bob', age='30', job='Salesman', friends=['Mario', 'Luigi'])

  • @kamurashev
    @kamurashev Год назад +3

    Nice! Named tuple vs dataclass for the next video?

  • @smanzoli
    @smanzoli 2 месяца назад

    It's important to talk about __post_init__ because real code WILL need it, dataclass cannot do all the __init__ most times.

  • @NoidoDev
    @NoidoDev Год назад

    Is it better to use that for data or some dict? For example, It seem that I won't be able to get "keywords".
    Also, there's a difference between __slots__ and slots=True, which is that you can use default value with the new method.

  • @MathewGuest
    @MathewGuest Месяц назад

    How do data classes compare to pydantic third-party library?

  • @forethiocodingstaff
    @forethiocodingstaff Год назад +1

    Young, energetic python developer

  • @aryandatla5188
    @aryandatla5188 3 месяца назад

    can we implement linked lists using dataclass?

  • @enricoroselino7557
    @enricoroselino7557 Год назад +1

    bob job nice

  • @superyngo
    @superyngo 17 дней назад

    why not using **json as arguments?

  • @jeyosman1
    @jeyosman1 8 месяцев назад

    I just wanted to take a moment to express my sincere appreciation for your exceptional explanations and the engaging speed at which you communicate. Your clarity and enthusiasm truly stand out, making learning from you an absolute pleasure. Thank you for your dedication and talent-I genuinely admire the way you convey information

  • @losco_arti
    @losco_arti Год назад

    Cool. Thanks!

  • @SanwicklithMkalinga-g6h
    @SanwicklithMkalinga-g6h Год назад

    Do u have a course… or mentoring program

    • @Indently
      @Indently  Год назад

      I have a couple of courses at: indently.io

  • @lostsoul8634
    @lostsoul8634 Год назад +5

    I'm learning python... bob= Person(**json) is better?

    • @MathewGuest
      @MathewGuest Месяц назад

      That is a good way to do it. If the data structures ever go out of sync, they would need updated

  • @nargileh1
    @nargileh1 4 месяца назад

    bob = Person(json['name'],json['age'],json['job'],json['friends'])
    why not use this instead?
    bob = Person(**json)

  • @DrDeuteron
    @DrDeuteron Год назад

    Don't forget the dataclasses.Field object...can be very useful when dealing with telemetry.
    There's also the "astuple" method that is attached to the class.

  • @betapacket
    @betapacket Год назад

    5th

  • @Timmie_Tudor
    @Timmie_Tudor Год назад

    Why are you teaching people how to use me?

    • @Indently
      @Indently  Год назад

      Because you're great and deserve to be treated with respect.