top | item 14012973

Ask HN: Why use Python?

42 points| xcoding | 9 years ago

40 comments

order

git-pull|9 years ago

Scales small-to-medium codebases well. Modules and packages work well. PEP8. Linting tools like flake8.

Documentation is top tier. Docutils + Sphinx + ReadTheDocs. Autodoc and intersphinx (linking across python projects) are just wonderfully implemented.

Contrib Library quality. Mature and well documented. Permissively licensed. Django, SQLAlachemy, Requests, Flask, Werkzeug, Boto, Jupyter, Numpy, Pandas, Scipy, fabric, ansible, saltstack, pytest (a new favorite of mine).

Standard library quality. Well documented and just the right amount of features in many cases. In some situations you may find more elegant API's in the contrib community.

OOP is implemented nicely. It scales well. It's easy to traverse large codebases and get situational orientation fast.

Language consistency. Python 3 is generally a consistent language. There are warts in every language, but nothing in python is insurmountable. Python 2.7 with __future__ imports and a compat module eliminates a lot of problems.

Debugging: Tracebacks are human friendly. ptpython/ptpdb and ipython/ipdb are a delight to work with.

C API integration. Well documented and well supported. Also see Cython, CFFI. Also C++ with boost python and pybind11

Editor integration. Jedi, pycharm

Stability. CPython (the main implementation) doesn't break. Clear distinction between 2 and 3 and easy enough to code to both versions. Contrib libraries generally follow semver and have consistent API's

Community. Friendly and great support on IRC and so on.

tedmiston|9 years ago

Short answer: Python is the best high-level, general purpose language. It's got a good following in web apps and APIs, data processing and research, and many other fields, as well as being the language of choice for many glue code projects and as a modern alternative to bash scripts.

I wrote a post that was popular on HN a few years ago thinking out loud about what Python is good at which received several comments on areas I missed too. The link in the HN thread [1] is dead but you can find the post at [2].

[1]: https://news.ycombinator.com/item?id=9524607

[2]: http://web.archive.org/web/20161101070610/http://lisnr.com/b...

cauterized|9 years ago

It's mature. The community is mature (in multiple senses of the word). The ecosystem is mature. The package management is solid. There are drivers or SDKs for basically every tool or service I would want to interface with.

The syntax is rich but concise. It doesn't require compilation of binaries. It does OOP pretty well. It does procedural pretty well. It does web pretty well. It does throwaway command line scripts pretty well. It does performance well enough for the things I do with it. It's portable.

Python isn't perfect, but 99.99% of the time it gets out of my way. I must, can, and do work with other languages. I constantly find them frustrating me in small ways. Python generally doesn't do that.

mattbillenstein|9 years ago

Good readable syntax, strong built-in data structures, good libraries for just about everything, less "magic" than other similar languages, moves at a deliberate pace and values backwards compatibility (minus the 2->3 thing).

jMyles|9 years ago

Lots of great answers here, but I think that there is an underlying cause of most of the benefits described, and that there is "one obvious way" to think about this question, and it's this:

* Python lives outside the control of any single corporate or government entity. Yes, three of the biggest players work at Dropbox, but clearly Dropbox doesn't have the kind of control over Python that Oracle has over Java, SalesForce with Ruby, or Google with Go.

Because of this, Python is more a community than a single programming language. Being at PyCon fills one with the sense that, after the fall of the state (or at least the US government), very little will change within Python - we'll still be there to support each other in code and in spirit.

There will still be a space for data science and web trends to share air with multimedia hacking and sacred geometry. There will still be story telling, acro-yoga, robotics, and unit tests under one roof.

I can actually imagine Rust or Go (and Gophercon) becoming such a haven, but to my knowledge, it isn't yet. Python has the unique combination of a rich, diverse, radical, accepting culture with technical maturity and reliability.

Python makes me feel safe and brings out the best of who I am.

That's why I use Python.

cdnsteve|9 years ago

It's a top-tier language due to the amazing support it receives from companies and the community. The PSF is well organized and the language releases are stable. There aren't a massive number of releases (or security issues) to try and keep up with but enough where new features are being added. It's usually one of the first languages to receive love when a new service is rolled out in terms of a library or offering. Tooling is good, using Visual Studio Code.

It's on an uptrend on usage which is always good for your career. I use it for web apps and API's and many larger companies also use it like Uber, Rackspace, Twillio, etc. The scientific field is becomming larger and it seems to be growing extremely quick with a new momentum in AI. Great option for building a CLI tool out. Overall it can handle a lot.

It's a language I really enjoy using on a daily basis at work. It feels like it has been the result of lots of hard work from some really smart people. Our team was at a crossroads and tried a variety of languages, we all agreed on Python. Clarity of what's happening with code is important to us and Python excels in this area.

Daishiman|9 years ago

It fits in my head. Its concepts are simple but orthogonal and extremely powerful. It doesn't ask me to take up complicated abstractions in order to do complicated things.

There's a library for everything out there.

I have never seen a language with greater uniformity of styles and idioms, with those style choices being right the vast majority of the time. You generally know what to expect, and I spend little time fighting with bugs or surprising behaviors.

For the things where its performance is unsatisfactory, it offers escape hatches. The tooling is good; there's better out there but I rarely find myself yearning for more than ipdb.

For scientific computing, it's simply top notch. I can't see myself using anything else for doing my data analysis until you're pushing the limits of performance.

Tracebacks are clear. Unlike JS, I know exactly where a piece of code is failing.

It lets you break rules when you need it to but it makes it obvious and the cultural pressure to not do it is high. Out of all the dynamically typed languages I know it'd the one I feel most comfortable pushing until the point where you need stronger validation.

Dowwie|9 years ago

I use Python because of the people who made it what it is today. The community is what I like most about Python.

I'm bootstrapping, taking a one-man army approach to creating a new service. I chose a mature language with features and open source projects I may possibly want or need along the way. I am working alone -- not by preference but rather necessity -- and knew I would need help along the way (started very green, 4 years ago). The Python standard library and open source ecosystem offers everything and more than I may ever need to create my vision. The Python community is really strong. It's a global movement. I've gotten so much help on IRC! Stack overflow always has an answer or a legion ready to answer practically anything Python related. Years of Python related blog posts are a google search away from access. PSF-supported Python conferences release or at least try to release video recordings of talks (cough.. ehem..). As for conferences? PyCon has been the ooey gooey salted caramel center of the perfect vanilla pint.

type0|9 years ago

It looks like a general pseudocode, even someone unfamiliar with the language can read it and usually understand what's going on.

oyebenny|9 years ago

Because I'm told to for school.

theophrastus|9 years ago

For me, entirely because of python's large, referenced, and well-documented numerical libraries (e.g. scipy and numpy).

HD134606c|9 years ago

+1 I just discovered SciPy/NumPy. This library is brilliant, now I can forget all the matlab knowledge I had and just focus on Python.

arms|9 years ago

I use Python because:

- it's a well designed language

- it has a great ecosystem and community

- it runs fast (enough for my purposes)

- it looks enough like pseudo-code that translating what I wrote on paper into a program is that much simpler.

The fact that it can be used both for teaching computer science in colleges and children how to code speaks volumes about its versatility and approachability.

I use it mostly for web apps, APIs and miscellaneous scripts. Python has been a great addition to my tool-belt. There are some languages I hope I never have to write again; Python on the other hand is something I'm going to always keep in mind, even if I spend most of my days writing another language.

rrggrr|9 years ago

For business automation it's spectacular. Pandas dataframes make database queries and dynamic reporting easy. There are rich API examples for most services. It's free. It's portable between osx, Linux and windows.

sparkling|9 years ago

Easy to read, easy to write, great high-quality libraries for pretty much everything.

pryelluw|9 years ago

It works well,is not handicapped by verbose idioms, works on most platforms and environments, can glue together other technologies, and the community is pretty good.

I just wish it supported the functional paradigm.

meagher|9 years ago

The wide number of things it enables: data science & machine learning, web apps & APIs, simple scripts, and it doesn't trip beginners up with extra syntax.

PaulHoule|9 years ago

Customers want it. I like Java myself, but the Python ecosystem is similar in scope and quality. There is nothing really wrong with Python.

paultopia|9 years ago

jupyter. nothing beats a repl in a web page for instant feedback and iteration.

marchenko|9 years ago

Scipy, numpy, pandas. And it is easy to think in Python.

LordHeini|9 years ago

CiPy. Simply the best option if you want to plot and manipulate your data in whatever way possible without any assle(most of the time).

drewjaja|9 years ago

It's clear, easy to read and junior developers can pick it up easily and contribute code sooner.

ransom1538|9 years ago

"The encoding is done using a function from the urllib library not from urllib2."

I love python. An ancient mess.

BoysenberryPi|9 years ago

Because people hire for it. I use whatever I can get a job with easily.

loblollyboy|9 years ago

Better question is why you wouldn't

apetrov|9 years ago

pandas. it's a killer library.

slrz|9 years ago

I try to avoid it for new programs though, as the life of the sane language version (Python 2) is going to end at some point.

coldtea|9 years ago

>as the life of the sane language version (Python 2) is going to end at some point.

Don't hold your breath for that. There are tens (hundreds?) of millions of Python code in production that's nobody ever gonna port, and that people will still support well into 2040.

sumedh|9 years ago

People still have to maintain Cobol programs, Python 2.x is not going to go anywhere.

jmstfv|9 years ago

Because it is elegant.

rtiwary|9 years ago

simple but just as powerful as other OOP languages

jwilk|9 years ago

Inertia.

vgy7ujm|9 years ago

I don't because it doesn't live up to its promises. Some of the most unreadable code I have seen was Python. Pure line noise.

brogrammernot|9 years ago

Yeah, I often blame the wood and nails when I see a poorly built house.

coldtea|9 years ago

I've never seen unreadable code in Python.

Care to post a sample?

And even if it actually was unreadable, just consider how the equivalent would look in Perl, or C (or APL...).

jeffjose|9 years ago

Are you confusing Python with Perl? The latter prides itself on creating line-noise that works like magic. Python is meant to be super-readable.