You gotta love a 2-line python solution

DFS nospam at dfs.com
Mon May 2 01:08:24 EDT 2016


On 5/2/2016 1:02 AM, Stephen Hansen wrote:
> On Sun, May 1, 2016, at 09:51 PM, DFS wrote:
>> On 5/2/2016 12:31 AM, Stephen Hansen wrote:
>>> On Sun, May 1, 2016, at 08:39 PM, DFS wrote:
>>>> To save a webpage to a file:
>>>> -------------------------------------
>>>> 1. import urllib
>>>> 2. urllib.urlretrieve("http://econpy.pythonanywhere.com
>>>>      /ex/001.html","D:\file.html")
>>>> -------------------------------------
>>>
>>> Note, for paths on windows you really want to use a rawstring. Ie,
>>> r"D:\file.html".
>>>
>> Thanks.
>>
>> I actually use "D:\\file.html" in my code.
>
> Or you can do that. But the whole point of raw strings is not having to
> escape slashes :)


Nice.  Where/how else is 'r' used?


I'm new to python, but I learned that one the hard way.

I was using "D\testfile.txt" for something, and my code kept failing. 
Took me a while to figure it out.  I tried various letters after the 
slash.  I finally stumbled across the escape slashes in the docs somewhere.





More information about the Python-list mailing list