I am at a high-beginner/low-intermediate level in Python, and one thing that drives me nuts is how poorly I am able to read the Python official documentation and grok how to use the described code.

What’s the secret? Are there any guides/videos/books that can help my understand how to approach reading it? Or, is it just one of those things that I need to just keep coming back to while coding, and eventually I will get the hang of it?

  • maor@lemmy.org.il
    link
    fedilink
    arrow-up
    16
    ·
    edit-2
    10 months ago

    I feel the same and I’ve been using Python for years professionally. It’s the lack of examples for me; usually functions and classes aren’t meant to be used as-is but rather fed as an argument into some other function or class, and this info is seldom portrayed in the func’s documentation. E.g. the documentation of BaseHTTPRequestHandler is one that I trip over every single time, I have to resort to reading the source code of SimpleHTTPRequestHandler to remember how handlers are supposed to be defined 🐺

      • thisisnotgoingwell@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        10 months ago

        I recommend getting very familiar with pythons help(), dir() and type() functions. The help function almost always includes examples for the methods you’re trying to use, tells you what arguments it expects, and what arguments are passed by default. The type function can help you understand the inheritance of OOP and what type of object you’re looking at, and dir on that object will tell you what attributes/methods are defined for your object type.

        Other than that, find some good books. I’m a big fan of Michael Driscoll’s Python 101 and 201 books.