7 ms·
The thing I love most about the language is its conciseness, on several levels. It's syntactically concise because of its use of whitespace and indentation ins
by riazrizvi 8y ago
The thing I love most about the language is its conciseness, on several levels.
It's syntactically concise because of its use of whitespace and indentation instead of curly braces.
Expressions are often concise because of things like list slicing and list expressions.
It can be linguistically concise, because it is so easy to fiddle with the data model of your classes, to customize their behavior at a deeper level. For example, it is so quick to design a suite of classes that have algebraic operators, which leads to elegant mathematical expressions of your custom GUI objects for example. But you can also change the way classes are instantiated by overriding Class.__new__ which I've used to make powerful libraries that are a joy to use.
Further elegance can be added through creative use of the flexible argument passing machinery, and the lovely way that functions are also objects.
Your application architecture tends to be concise because there are so many existing libraries, you can often design your application at a more interesting higher level. For example, you don't have to worry about the size of int's.
My big regret with Python 3.0 is that the scoping rules in list expressions changed to prohibit modification of variables in surrounding scope. This degraded the utility of list expressions. The work around is so long-winded.
Besides the odd gripe here and there, the language really gives me a warm glow.
- hellofunk 8y ago> My big regret with Python 3.0 is that the scoping rules in list expressions changed to prohibit modification of variables in surrounding scope. This degraded the utility of list expressions. The work around is so long-winded. Can you elaborate? I'm not sure what this is referring to.
- duckerude 8y agoIn Python 2, "[x for x in range(10)]; print(x)" prints 9. x is available outside the list comprehension. In Python 3, it raises a NameError, because the x in "print(x)" is not defined. It's contained in the list comprehension. But I don't know a good use of the Python 2 behavior.
- eesmith 8y agoIn Python 2.x the loop variable is part of the containing scope: >>> a Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'a' is not defined >>> [a*2 for a in (1,2,3)] [2, 4, 6] >>> a 3 In Python 3.x, it is not: >>> a Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'a' is not defined >>> [a*2 for a in (1,2,3)] [2, 4, 6] >>> a Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'a' is not defined It is sometimes useful to know why something failed. The following Python 2 code will not work in Python 3: >>> import math >>> try: ... values = [math.sqrt(x) for x in (1, 2, -3, 4)] ... except ValueError: ... print("cannot compute sqrt(%r)" % x) ... cannot compute sqrt(-3) I have mostly found this feature of Python 2 to be useful on the interactive shell, when trying to diagnose what caused an error in my list comprehension. Eg. >>> with open("tmp.dat") as input_file: ... fields = [line.split()[3] for line in input_file] ... Traceback (most recent call last): File "<stdin>", line 2, in <module> IndexError: list index out of range >>> line 'one two three\n' Oops, there are only 3 columns, not 4.
- w-m 8y agoWhen you use iPython you can just drop into the context of the error with %debug after it occurred, and then print the line there. No need for the bleeding scope on the language level.
- aidos 8y agoI’m the same, I would never use that side effect in production code but I do miss having it in ipython though my use is slight different. I often did: >>> [d for d in drawings] >>> [d.<tab> ...] Because I’m lazy and I want the autocomplete to be there for me. It’s actually the only thing I miss from python 2 and I will admit that a couple of times the sideffects have caught me out in production code so I’m happy with the change. It’s worth noting that the latest python pep is going to give you a way to assign the variables in the outer scope again: https://www.python.org/dev/peps/pep-0572/#simplifying-list-comprehensions https://www.python.org/dev/peps/pep-0572/#simplifying-list-c...
- deleted 8y ago
- throwaway5752 8y ago"Besides the odd gripe here and there, the language really gives me a warm glow." That's a perfect summary of my feeling towards it, too. If the PSF puts up a GoFundMe for sending Guido on a nice vacation of his choosing, I will be happy to chip in a few bucks. Same goes for Linus when he hands over the reins, and a few other maintainers who probably cannot be adequately compensated for the impact of their work.
- deleted 8y ago[deleted]
- bb88 8y agoAsk Naomi Ceder who is the chair of the PSF. She's super nice.
- stevesimmons 8y agoI agree. I came to Python in 2000, after Perl (1996-1998), PHP (1999), Matlab (1992-1996), C++ (1990), Fortran (1989), C (1988), Pascal (1988), Assembly (1984-86) and Basic (1981-83). After all those, I found Python, as the saying goes, really does "fit your brain" [1]. Since discovering Python 18 years ago, I have looked at Haskell, successfully avoided Java, and promised myself to "one day" do more JS. Still, Python remains 95% of what I do, and I don't see a problem with that :) [1] "Python fits your brain" was the theme of the 9th International Python Convention in 2001.
- dorfsmay 8y ago> "Python fits your brain" For me, I find using python is like touching both data and code with my hands. As much as it's trendy to bash Object Oriented languages, the way python allows to lookup all variables and method on a class or an object makes it like using your hands: dir(MyClass) help(MyClass) dir(my_object) help(my_object) etc...
- opnitro 8y agoIf you'd like to go further along that path, and I'd really recommend trying to learn a lisp. How to Design Programs[0] is good gentle introduction if you're new to the ideas of lisp or functional programming, and SICP[1][2] is the old classic. [0] http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html [1] http://web.mit.edu/alexmv/6.037/sicp.pdf http://web.mit.edu/alexmv/6.037/sicp.pdf [2]https://www.youtube.com/watch?v=2Op3QLzMgSY&list=PLE18841CABEA24090 https://www.youtube.com/watch?v=2Op3QLzMgSY&list=PLE18841CAB...
- iscrewyou 8y agoI went through a course in python about a decade ago and I enjoyed it! Then along the way, I picked it up here and there. Then used it at work for a few months to sort through a lot of data. Recently I started trying to learn swift through the Stanford course. And the curly brackets confused the heck out of me. They still do! They just seem to pop up out of nowhere. All to say , I completely agree with your second paragraph. Python is very concise.
- eigenvalue 8y agoIt's also nicely self-contained, especially if you use a distribution like Anaconda. You don't have to spend hours fighting with the configuration and tooling. It's also very easy to debug and step through code using Spyder, which is similar to MATLAB. It makes it easy for someone who is smart and generally competent with computers to be productive in a short amount of time without first amassing huge amounts of arcane knowledge-- knowledge that isn't actually helpful to making working code!
- Barrin92 8y agoagreed with all the posts above, the only real letdown for me was always the difficulty to produce standalone executables. I would really love a python equivalent to uberjars or go's build tool.
- StavrosK 8y agoI recently used PyInstaller to wrap Black (the code formatter) and it worked perfectly in two minutes. Literally one command to take the whole script and produce a standalone executable. There's also something like this: https://build-system.fman.io/ https://build-system.fman.io/
- talltimtom 8y agoThe thing about pyInstaller is that it works absolutely perfectly... until it doesn’t. In which case you are stuck spending days on trying to kick everything in your project into shape with the hope of it working. That is what I hate most about Python, there is only one sure-fire way of doing packaging and that’s setting it up even before you write your first line of code and the testing constantly as your project evolves. Myself and others have absolutely no trust in the several build pathways because they all fail horrible for a wide range of reasons. To the counter, if I have a C++ or C# project I’m very confident that it will almost always be a breeze to package it up.
- deleted 8y ago[deleted]
- UncleEntity 8y ago> My big regret with Python 3.0 is that the scoping rules in list expressions changed to prohibit modification of variables in surrounding scope. This degraded the utility of list expressions. The work around is so long-winded. Ironically, the PEP to add this to py3k is what's causing all the fuss in pythonland lately.
- riazrizvi 8y agoActually I think it was 'fixed' as a syntax change in Python 3, https://docs.python.org/3/whatsnew/3.0.html#changed-syntax https://docs.python.org/3/whatsnew/3.0.html#changed-syntax "List comprehensions no longer support the syntactic form..."
- kjeetgill 8y agoHe's talking about something a little different. Python is introducing assignment expressions (vs assignment statements).
- nikofeyn 8y agodo you know an ML language like sml, ocaml, or f#? if not, you should really give one a go, especially f#. the conciseness and cleanliness is just as good if not better than python, and there are far more options for data modeling and expression.
- riazrizvi 8y agoCORRECTION: My regret was referring to a problem where this code worked in Python 2 but not Python 3: x = 100 y = [x+i for i in range(2)] In Python 3 I kept seeing NameError: name 'x' is not defined However, after working around this problem with fixes like this - x = 100 y = (lambda x=x: [x+i for i in range(2)])() I have just discovered that the different scope treatment was due to a problem with IPython when using it in embed mode, for example by calling it with the following command: $ python -c "import IPython;IPython.embed()" It goes away when you call ipython directly $ ipython I mistakenly attributed this problem to Python 3 for years, I guess I introduced the problem because I had a different way of invoking Python 2 and Python 3 - yeesh.