Ask HN: High quality Python scripts or small libraries to learn from

Ask HN: High quality Python scripts or small libraries to learn from
Ask HN: High quality Python scripts or little libraries to gain from

36 points by dir_balak 2 hours ago | conceal | past | preferred | 10 remarks

I discovered that checking out other individuals’s code is extremely useful for my own coding. I have not discovered a resource that notes some terrific code in Python which is not a huge codebase. Any recommendations?

I believe I discuss this all the time when this shows up, however I found out the most ‘finest practices’ through utilizing ruff.

https://docs.astral.sh/ruff/

I simply set up and allowed all the guidelines by setting choose = [ “ALL” ]

And after that took a look at the ‘mistakes’ it revealed me for my existing code base and after that left out some guidelines which do not intrigue me.

I likewise have it established in my IDE, so it’ll reveal me the linting mistakes while coding.

In a bigger code base there will certainly be numerous ‘mistakes’, however utilizing it tidied up my code actually great and it stopped me from some footguns.

This is great guidance. I found out Python long before ruff emerged, however I did the exact same with Pylint. I do not adhere strictly to its suggestions anymore, however I found out a lot about the language from attempting. I reality, I believe a few of its suggestions are downright incorrect, and what I discovered was that I made my code more difficult to keep by following them.

I can’t consider any (little) libraries I might suggest to discover finest practices, however what does enter your mind is click [0]the CLI library for Python. Their paperwork is quite excellent, there are lots of brief example scripts to be discovered online, and in my experience making little apps with click can be a great method to discover various python functions like args/kwargs, designers, string adjustment, and so on.

I concur with others that code formatters like black or ruff may be useful to you. The literature surrounding them, such as PEPs worrying code format, frequently consist of examples you might discover beneficial.

[0] https://click.palletsprojects.com/en/8.1.x/

As a derivation of this, in basic I recommend checking out structure source code. Not due to the fact that you ought to compose code like that, however to discover what the language can do. Structure source code has actually typically been fine-tuned by numerous individuals over a longer time period, sharpened to prevent rough edges. I believe you can discover a lot about developing an API, composing great abstractions, and encapsulating intricacy.

Find out more

Leave a Reply

Your email address will not be published. Required fields are marked *