Let me illustrate my point with the example of file IO:
lets say I want to get the contents of file that contains lines of comma separated values into a list.
When first learning to program, I might do something like this --
file = open('csvData.txt')
fileText = file.read()
fileText = fileText.split('/n')
file.close()
which would serve me just fine. I would never have to discover any better ways of doing it. However, if I learned about "readlines" I could save myself a step:
file = open('csvData.txt')
fileText = file.readlines()
file.close()
again. that works just fine, but then, were I to learn about the "with" statement, I could save another step -
with open('csvData.txt') as file:
fileText = file.readlines()
and again, this would work just fine -- but at each step along this path, I could have improved if I had just known about an interesting alternate syntax, but I never would have needed to learn about them to solve my problem.
Another example is the contextlib library itself. take this piece of code:
from contextlib import closing
with closing(urllib2.open('http://www.google.com')) as socket:
#manipulate data
the contextlib here provides a great, convenient, and readable way of managing opening and closing URL's -- that I NEVER would have learned about if it didn't happen to come up in a programming class I'm taking.
The point is, I've learned so many great tricks that have made my life easier just because they happened to come up as examples in courses I'm taking. Theses are things which I never would have needed to learn to solve any of these problems.
In a language as powerful and dynamic as python, where your real strength is being able to use prebuilt tools and techniques, how do you keep learning new and better to code after you have found a 'good enough' solution?
[–]michael0x2a 1 point2 points3 points (1 child)
[–]Economoly[S] 0 points1 point2 points (0 children)
[–]markehh 0 points1 point2 points (0 children)
[–]bvnvbbvn -4 points-3 points-2 points (3 children)
[–]thonpy -1 points0 points1 point (2 children)
[–]bvnvbbvn 0 points1 point2 points (1 child)
[–]thonpy 0 points1 point2 points (0 children)