Re:This Is What Python Beginners Have to Deal With
by d0mine on Thursday September 08, 2016 @12:56PM
(#12454756)
If you don't know whether a method returns an iterator or a mutable/immutable sequence (regardless of the specific type) then the documentation is incomplete (it is a bug). If it is in stdlib; you could submit a documentation patch for a *.rst file on https://bugs.python.org/ See https://docs.python.org/devguide/docquality.html
Re:This Is What Python Beginners Have to Deal With
by lqdc13 on Thursday September 08, 2016 @08:54AM
(#12452472)
"The problem is that I don't know what methods the returned objects have available, and as such whether they are a duck or a tiger."
I don't get this... Why not do the following:
In [1]: import requests
In [2]: resp = requests.get('http://www.google.com')
In [3]: resp.
resp.apparent_encoding resp.iter_lines
resp.close resp.json
resp.connection resp.links
resp.content resp.ok
resp.cookies resp.raise_for_status
resp.elapsed resp.raw
resp.encoding resp.reason
resp.headers resp.request
resp.history resp.status_code
resp.is_permanent_redirect resp.text
resp.is_redirect resp.url
resp.iter_content
Now you can try each of those things and explore their methods.
Re:This Is What Python Beginners Have to Deal With
by snovv_crash on Thursday September 08, 2016 @03:23PM
(#12456393)
Because I'm not always scripting - sometimes the work I'm doing takes 10 minutes of runtime to get to the end and I want to know what I'm writing before I run it.
If Python wants to remain a scripting language forever then the docs are sufficient. But if it wants to graduate, and it seems a lot of people think it already has, then the libraries need to be better documented.
Can I index the returned object, or only iterate over it? Is it mutable? Is it a dict or a tuple of (key,value) tuples? Did the author think it was worth it to make its own class for the return type, because they want the indexes where the value was found as well as the metadata?
Python, to a degree, brushes over these problems by being able to print out most types of data and then figure out where the problem is, but TBH I'd prefer to write the correct code to begin with, and the docs don't give me enough information to do so. As such, Python turns into a dodge-the-error-driven-programming, and I feel much less productive than I could be.
Yes, duck-typing gets you part of the way, but it doesn't let you pretend type doesn't exist entirely.
I feel like using Go's interfaces would be more powerful for a duck-typing language than having type-annotations.