HACKER Q&A
📣 bloominggarden

How do you become a better Python developer?


I assume that a lot of this just comes down to general SE experience but I am looking to actively learn how to write more "pythonic" code.


  👤 yellowapple Accepted Answer ✓
Every good programmer was once a bad programmer. They typically evolve into good programmers by iteratively identifying what they don't like about their own code and fixing those issues. Those fixes will often need fixes down the line, but that's okay.

Your first step for that identification should be to list your priorities for the end result. Readability? Robustness? Speed? Compactness? Reusability? Extensibility? Once you know by what metrics you want your code to be "good", you can start to examine where your code falls short.

The other key thing is to be unafraid to write bad code. It's hard to know when or why something's bad until you've held it in your hands, fiddled with it, given it a good swing. From there you can refine it by whatever metrics you've prioritized (per above).


👤 hayst4ck
Install linters, they will correct one class of unpythonic code.

Next google "idiomatic python." Idiom is the software word for the "right" way to do something.

After linters and idioms, code will probably look pythonic. Next is overall structure, which IMHO, python is not super opinionated on.

What becomes more useful to understand are the different software paradigms: procedural, functional, and object oriented.

Once you understand paradigms a bit, it's worth understanding object oriented in more detail. Misko Hevery has a lot of great things to say on that.

At this point, you should be able to write extremely boring python. Nothing is better than extremely boring code.

After that, watching videos, reading books, reading code, and writing code is the way.

Learning google's Bazel is probably also important, since any sufficiently large python project will crumble under its own complexity without Bazel or a system like it.


👤 Cody_C
Whenever I am on a project, I try to write any tooling (code generators, utils, scripts, etc) in the tech that it uses. This forces you to broaden your horizons in the tooling. I even have a toolbox git repo that has a bunch of different tools written around this concept that I have often reused.

I would also recommend trying to 'think' in the language. Don't just try to push a solution into the language. Dig deep and see if there is something specific that makes the most sense to use.

Overall, I wouldn't try to push away your style entirely. I don't think you truly can. I would say the best bet is try to be a great engineer, with strong baseline principles which you then apply in the best way for each environment. Every decision is a tradeoff and many of the big schisms in tech come down to taste. Actively work to learn new ways of doing things. Work to understand other's code longer than you think you should.


👤 jstx1
> I am looking to actively learn how to write more "pythonic" code.

Effective Python is a great book which aims to teach people who already know the language how to use it well.


👤 hbrn
Raymond Hettinger talks are a good start (e.g. https://youtu.be/wf-BqAjZb8M)

Every now and then read Zen of Python and try to understand it. Tim Peters somehow managed to fit enormous amount of wisdom in it.


👤 bilsbie
I’d find some GitHub repositories of popular libraries that are known to be well written and look through their code.

I believe this was a good one back in my day. https://github.com/psf/requests


👤 clusmore
Watch anything by Raymond Hettinger on YouTube.

👤 ReflectedImage
Go write a FastAPI based Rest service which talks to PostgreSQL via SQLAlchemy.

Then set up some compete workers that read in jobs from a RabbitMQ queue. Have the Rest service add jobs to the queue and get back the results.

Also you can just read the official Python tutorial for learning stuff like with contextmanager.


👤 mitchellpkt
A while back when I was familiar with coding but wanted to improve my python skills, I found this video helpful: https://www.youtube.com/watch?v=qUeud6DvOWI

Once I understood fstrings, list/dict/set comprehension, and tuple unpacking, it became much easier to read and learn from others' python code.


👤 lazypenguin
As with any programming language. Solve a wide range of different problems in different domains using different python tools.

👤 pyuser583
Read well written code. I recommend Django.

👤 4dregress
I'm self taught and on the cusp of becoming a senior engineer. I've improved by making mistakes and learning from my peers.

Review code and ask lots of questions, you wont learn anything if you don't ask why?


👤 roland35
What forced me to understand more fundamentals was actually studying leetcode. It led me to learn more about data structures, things like itertools, and other other algorithms.

Combined with a good book (eg learn python the hard way) it’s an approach that worked for me.


👤 aynyc
Really really read the Python tutorial and library reference. I mean really read it. There are so much nuggets in there that you'll be way above average Python developers by the end.

👤 schwartzworld
There's no real shortcut to proficiency. Write a lot of code and always look for ways to improve it.

👤 giantg2
I didn't.

I ended up going to a front end team working in Angular. Now I miss it.


👤 thinking001001
Learn C?

👤 kidgorgeous
leetcode puzzles. Will also help you get sharp for coding interviews

👤 fegehrjhrh
Stop using python. Learn a typed language and realise that whilst python is great for the odd script, it sucks for anything larger.

Rust to me is a better python, can make python modules (py03 ftw) and the 30x speed up you get from using it is great... Oh yeah there is a borrow checker but it is not that bad once you grok it.

Edit: autocompelete!!!!!!