You gotta love a 2-line python solution

Marko Rauhamaa marko at pacujo.net
Mon May 2 06:12:08 EDT 2016


BartC <bc at freeuk.com>:

> On 02/05/2016 04:39, DFS wrote:
>> 2. urllib.urlretrieve("http://econpy.pythonanywhere.com
>>     /ex/001.html","D:\file.html")
> [...]
>
> It seems Python provides a higher level solution compared with VBS.
> Python presumably also has to do those Opens and Sends, but they are
> hidden away inside urllib.urlretrieve.

Relevant questions include:

 * Is a solution available?

 * Is the solution well thought out?

Python does have a lot of great stuff available, which is nice.
Unfortunately, many of the handy facilities are lacking in the
well-thought-out department.

For example, the urlretrieve() function above blocks. You can't use it
with the asyncio or select modules. You are left with:

   <URL: https://docs.python.org/3/library/asyncio-stream.html#get-http-h
   eaders>

Database facilities are notorious offenders. Also, json.load and
json.loads don't allow you to decode JSON in chunks.

If asyncio breaks through, I expect all blocking stdlib function calls
to be adapted for it over the coming years. I'm not overly fond of the
asyncio programming model, but it does sport two new killer features:

 * any blocking operation can be interrupted

 * events can be multiplexed


Marko



More information about the Python-list mailing list