one last mutationthe following urllib request downloader script uses the slightly higher-level urlretrieve interface in that module to automatically save the downloaded file or script output to local file on the client machine this interface is handy if we really mean to store the fetched data ( to mimic the ftp protocolif we plan on processing the downloaded data immediatelythoughthis form may be less convenient than the version we just metwe need to open and read the saved file moreoverwe need to provide an extra protocol for specifying or extracting local filenameas in example - example - pp \internet\other\http-getfile-urllib py ""fetch file from an http (webserver over sockets via urlllibthis version uses an interface that saves the fetched data to local binary-mode filethe local filename is either passed in as cmdline arg or stripped from the url with urllib parsethe filename argument may have directory path at the front and query parameters at endso os path split is not enough (only splits off directory path)caveatshould urllib parse quote filename unless known ok--see later ""import sysosurllib requesturllib parse showlines tryservernamefilename sys argv[ : first cmdline argsexceptservernamefilename 'learning-python com''/index htmlremoteaddr 'any address on the net if len(sys argv= get result filename localname sys argv[ else(schemeserverpathparmsqueryfragurllib parse urlparse(remoteaddrlocalname os path split(path)[ print(remoteaddrlocalnameurllib request urlretrieve(remoteaddrlocalnameremotedata open(localname'rb'readlines(for line in remotedata[:showlines]print(linecan be file or script saved to local file file is bytes/binary let' run this last variant from command line its basic operation is the same as the last two versionslike the prior oneit builds urland like both of the last twowe can list an explicit target server and file path on the command linec:\pp \internet\otherhttp-getfile-urllib py '\nb\nb'\nb"mark lutz' python training services\nb'<link rel="stylesheettype="text/csshref="_themes/blends/blen '\nthe urllib package revisited