6 ms·
Improving Your Python Productivity
- kbd 14y agoNot a very helpful article. Far from a general "improve your Python productivty", it's more like "here are some minor random Python features that I think are useful". TLDR: * Use dict and set comprehensions. * Use collections.Counter. * Use json.dumps or the pprint module for pretty printing. * Create simple web services with Python's XML-RPC library. * Use open source libraries...
- tbatterii 14y agoyep, my sentiments exactly. nothing at all having to do with productivity.
- draven 14y agotl;dr: know the stdlib and the ecosystem well.
- etrain 14y agoAs we move toward languages with big standard libraries, productivity becomes more and more about knowing what you don't have to do yourself. Case in point - even as a Python veteran, I've never seen/used collections.Counter before. It'll save me from writing the same stupid three lines over and over, and is probably implemented faster than I naively do. I'd say that this will improve my productivity.
- darkarmani 14y agoThe biggest problem is having to use old LTS distros in production that only have python 2.6 for example. I'm glad that most LTS versions are soon to be using python 2.7. I know 2.7 has been around for a long time, but so much production software is running on RHEL/Centos systems with 2.6.
- moreati 14y agoTo make you feel a bit better - some of us are still on RHEL 5 and Python 2.4. Yes it is painful.
- cyann 14y agoYou can find python26 in EPEL [1] or follow this guide [2] to setup 2.7. This will install 2.6 or 2.7 in parallel, do not set these by default as it will break yum. [1] https://fedoraproject.org/wiki/Python26 https://fedoraproject.org/wiki/Python26 [2] http://villaroad.com/2010/10/rolling-python-2-6-2-on-centos-5-3/ http://villaroad.com/2010/10/rolling-python-2-6-2-on-centos-...
- conesus 14y agoCould not agree with you more. The more advanced I become with a language, the more I like to go back to even basic docs and read the small-print fancy uses for built-ins. This article touches on a number of them, and it's tricks like this that help you write better code (when used responsibly, of course).
- d0mine 14y agoUsually collections.defaultdict is faster than collections.Counter. But the latter is more concise to use.
- eddyweb 14y agoAs someone just said on reddt #4 reminds me of python -m SimpleHTTPServer. Very useful, even when you are not coding in Python!
- dmnd 14y ago#3 is also usable from the shell in a similar way: echo '{"foo":1, "bar":[1,2,3]}' | python -m json.tool
- Zoophy 14y agoWhitespace as syntax? Really?
- xxpor 14y agoHave you never seen python before?
- agumonkey 14y agoLet's call it canonical offside rule.
- recursive 14y agoYes really. If you have any further questions about the python language specification, you can answer them here: http://docs.python.org/3/reference/ http://docs.python.org/3/reference/
- masklinn 14y agoFlashnews:mostmodernlanguagesdoindeedusewhitespaceassyntax.
- sneak 14y agoIt's more likely than you think.
- d0mine 14y agoHere's a good explanation about whitespace in Python http://www.secnetix.de/olli/Python/block_indentation.hawk http://www.secnetix.de/olli/Python/block_indentation.hawk
- buster 14y agoDespite the negative comments here, it's always good to be reminded of some of nice built-in things. Reminds me how awesome pythons standard functionality really is.
- deleted 14y ago[deleted]
- edwinnathaniel 14y agoAfter reading a few comments here I'm surprised there's no "Effective Python" book already (given the age of Python itself). In Java and .NET, that's what we try to do everyday: writing idiomatic Java/C# code (style, architecture, patterns, standard libs, etc).
- sateesh 14y agoThough I have yet to come across book titled "Effective Python", books like "Python Essential Reference" by David Beazly and "Python Cook Book" covers lot of ares that you mention above.
- gbog 14y agoOne single productivity python I'd like to share here is to use 'string foo'.partition(' ') instead of splitting. The reason is the edge cases are better handled with partition: you always get a 3-tuple, no matter what. No need to precheck that the split is here, or to postcheck the length of the splitted list.
- takluyver 14y agoOn the other hand, .split() with no argument splits on any amount of whitespace (\s+, as a regex). That's often quite a useful edge case to have handled for you. You can also do .split(c, 1) to limit it to a single split. It could still split 0 times, though - it just depends which edge cases you want to handle.
- fionabunny 14y agoI was hoping to find some mention of IDE, IDE plugin, or more process oriented stuff, rather than language features.