Re: You gotta love a 2-line python solution

2016-05-03 Thread Steven D'Aprano
On Tue, 3 May 2016 01:56 pm, DFS wrote: > On 5/2/2016 11:27 PM, jf...@ms4.hinet.net wrote: >> DFS at 2016/5/3 9:12:24AM wrote: >>> try >>> >>> from urllib.request import urlretrieve >>> >>> http://stackoverflow.com/questions/21171718/urllib-urlretrieve-file-python-3-3 >>> >>> >>> I'm running

Re: You gotta love a 2-line python solution

2016-05-03 Thread Stephen Hansen
On Mon, May 2, 2016, at 08:57 PM, jf...@ms4.hinet.net wrote: > Stephen Hansen at 2016/5/3 11:49:22AM wrote: > > On Mon, May 2, 2016, at 08:27 PM, jf...@ms4.hinet.net wrote: > > > But when I try to get this forum page, it does get a html file but can't > > > be viewed normally. > > > > What does

Re: You gotta love a 2-line python solution

2016-05-02 Thread jfong
Stephen Hansen at 2016/5/3 11:49:22AM wrote: > On Mon, May 2, 2016, at 08:27 PM, jf...@ms4.hinet.net wrote: > > But when I try to get this forum page, it does get a html file but can't > > be viewed normally. > > What does that mean? > > -- > Stephen Hansen > m e @ i x o k a i . i o The page

Re: You gotta love a 2-line python solution

2016-05-02 Thread DFS
On 5/2/2016 11:27 PM, jf...@ms4.hinet.net wrote: DFS at 2016/5/3 9:12:24AM wrote: try from urllib.request import urlretrieve http://stackoverflow.com/questions/21171718/urllib-urlretrieve-file-python-3-3 I'm running python 2.7.11 (32-bit) Alright, it works...someway. I try to get a zip

Re: You gotta love a 2-line python solution

2016-05-02 Thread Stephen Hansen
On Mon, May 2, 2016, at 08:27 PM, jf...@ms4.hinet.net wrote: > But when I try to get this forum page, it does get a html file but can't > be viewed normally. What does that mean? -- Stephen Hansen m e @ i x o k a i . i o -- https://mail.python.org/mailman/listinfo/python-list

Re: You gotta love a 2-line python solution

2016-05-02 Thread jfong
DFS at 2016/5/3 9:12:24AM wrote: > try > > from urllib.request import urlretrieve > > http://stackoverflow.com/questions/21171718/urllib-urlretrieve-file-python-3-3 > > > I'm running python 2.7.11 (32-bit) Alright, it works...someway. I try to get a zip file. It works, the file can be

Re: You gotta love a 2-line python solution

2016-05-02 Thread DFS
On 5/2/2016 8:45 PM, jf...@ms4.hinet.net wrote: DFS at 2016/5/2 UTC+8 11:39:33AM wrote: To save a webpage to a file: - 1. import urllib 2. urllib.urlretrieve("http://econpy.pythonanywhere.com /ex/001.html","D:\file.html")

Re: You gotta love a 2-line python solution

2016-05-02 Thread jfong
DFS at 2016/5/2 UTC+8 11:39:33AM wrote: > To save a webpage to a file: > - > 1. import urllib > 2. urllib.urlretrieve("http://econpy.pythonanywhere.com > /ex/001.html","D:\file.html") > - > > That's it! Why my system

Re: You gotta love a 2-line python solution

2016-05-02 Thread Manolo Martínez
On 05/02/16 at 11:24am, Larry Martell wrote: > That reminds me of something I heard many years ago. > > Every non-trivial program can be simplified by at least one line of code. > Every non trivial program has at least one bug. > > Therefore every non-trivial program can be reduced to one line

Re: You gotta love a 2-line python solution

2016-05-02 Thread Larry Martell
On Mon, May 2, 2016 at 11:15 AM, DFS wrote: > Of course. Taken to its extreme, I could eventually replace you with one > line of code :) That reminds me of something I heard many years ago. Every non-trivial program can be simplified by at least one line of code. Every non

Re: You gotta love a 2-line python solution

2016-05-02 Thread DFS
On 5/2/2016 5:26 AM, BartC wrote: On 02/05/2016 04:39, 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") - That's it!

Re: You gotta love a 2-line python solution

2016-05-02 Thread Steven D'Aprano
On Mon, 2 May 2016 08:12 pm, Marko Rauhamaa wrote: > For example, the urlretrieve() function above blocks. You can't use it > with the asyncio or select modules. The urlretrieve function is one of the oldest functions in the std library. It literally only exists because Guido was working on a

Re: You gotta love a 2-line python solution

2016-05-02 Thread Marko Rauhamaa
BartC : > 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

Re: You gotta love a 2-line python solution

2016-05-02 Thread BartC
On 02/05/2016 04:39, 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") - That's it! Coming from VB/A background, some of

Re: You gotta love a 2-line python solution

2016-05-02 Thread Terry Reedy
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")

Re: You gotta love a 2-line python solution

2016-05-02 Thread DFS
On 5/2/2016 1:37 AM, Stephen Hansen wrote: On Sun, May 1, 2016, at 10:23 PM, DFS wrote: Trying the rawstring thing (say it fast 3x): webpage = "http://econpy.pythonanywhere.com/ex/001.html; webfile = "D:\\econpy001.html"

Re: You gotta love a 2-line python solution

2016-05-01 Thread Steven D'Aprano
On Monday 02 May 2016 15:21, Stephen Hansen wrote: > On Sun, May 1, 2016, at 10:08 PM, DFS wrote: >> On 5/2/2016 1:02 AM, Stephen Hansen wrote: >> >> 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 :)

Re: You gotta love a 2-line python solution

2016-05-01 Thread Stephen Hansen
On Sun, May 1, 2016, at 10:23 PM, DFS wrote: > Trying the rawstring thing (say it fast 3x): > > webpage = "http://econpy.pythonanywhere.com/ex/001.html; > > > webfile = "D:\\econpy001.html" > urllib.urlretrieve(webpage,webfile) WORKS >

Re: You gotta love a 2-line python solution

2016-05-01 Thread DFS
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.

Re: You gotta love a 2-line python solution

2016-05-01 Thread Stephen Hansen
On Sun, May 1, 2016, at 10:08 PM, DFS wrote: > On 5/2/2016 1:02 AM, Stephen Hansen wrote: > >> 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? Raw strings

Re: You gotta love a 2-line python solution

2016-05-01 Thread DFS
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.

Re: You gotta love a 2-line python solution

2016-05-01 Thread Stephen Hansen
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.

Re: You gotta love a 2-line python solution

2016-05-01 Thread DFS
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")

Re: You gotta love a 2-line python solution

2016-05-01 Thread Stephen Hansen
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 gotta love a 2-line python solution

2016-05-01 Thread DFS
To save a webpage to a file: - 1. import urllib 2. urllib.urlretrieve("http://econpy.pythonanywhere.com /ex/001.html","D:\file.html") - That's it! Coming from VB/A background, some of the stuff you can do with python -