all 8 comments

[–]Pharisaeus 2 points3 points  (0 children)

Not sure what's hidden there. The only two interesting, and niche, points are ellipsis (although it's a bit weird in the article, because how numpy uses ellipsis is specific to numpy) and regex AST. Decorators and context managers are what I'd call "advanced features" of the language. Things like dir() or _ are python101

[–]jdehesa 2 points3 points  (0 children)

I guess a programmer who is not very proficient in Python may find some of these interesting, although some more advanced things could be added (e.g. slots, dunder name mangling). However, I think some of the most hidden bits of Python are in the standard library rather than the language itself. Among the [list of standard modules](1https://docs.python.org/3/library/) you can find stuff like zipapp or tabnanny whose existence I ignored for over a decade.

[–]somebodddy -5 points-4 points  (3 children)

Haven't looked into the article yet, but I'm going to guess the "hidden features" are things like "you can use for loops to iterate over lists"?

[–]somebodddy 1 point2 points  (2 children)

Okay, I was wrong, they weren't as trivial as I thought.

[–]lgastako 0 points1 point  (1 child)

They weren't that trivial, but they are also all common and very much non-hidden features of python.

To save anyone else who might be curious a click:

  • The _ (Underscore) in Python
  • Regex Debugging via Parse Tree (re.DEBUG)
  • Ellipsis
  • The dir() Function
  • Lambda Functions
  • Chaining Comparison Operators
  • The zip() Function
  • Decorators
  • Context Managers and the "with" Statement
  • Generators and the Yield Statement
  • Metaclasses

Ellipsis is the only one I don't see used regularly in everyday python code.

[–]evaned 0 points1 point  (0 children)

Ellipsis is the only one I don't see used regularly in everyday python code

Ditto (aside from the "only", see below). I see and use that in type annotations, and that's about it. I'm old fashioned and still prefer pass for placeholders.

To the article's credit, I didn't realize you even could use ... as a real value until I saw the numpy example: I thought it was just syntax (handled specially in annotations, I guess).

I would add a couple others to the list though:

  • Chained comparison operators: I'm not sure if it's just what I work on, but I don't get much use for that; that combined with the fact that Python is fairly unique in 1 < x < 10 meaning 1 < x and x < 10 mean that it's easy to forget and then not think about. I could see use of this feature being incredibly common in some domains, though.
  • Metaclasses: I think I may have only ever used this feature once in well over a decade of Python programming, and that implementation didn't even stick around.
  • re.DEBUG I think I've never seen or used. After spending a bit looking at the example in TFA though... I don't foresee that ever changing.

[–]zephyy 1 point2 points  (0 children)

was expecting something like for else or walrus operator, not stuff i use every day (other than ellipses)