Need script to download file at known address

Jeff Shannon jeff at
Fri Sep 17 04:59:17 CEST 2004

Radioactive Man wrote:

>Looking back through the documentation, I see that open() is really an
>alias for file(). 

For now... but (despite what those docs imply) it's really best to stick 
with using open() and don't worry about the existence of file() unless 
you're trying to subclass it...  (GvR has recently said that he never 
intended for file() to replace open(), and that the direct use of file() 
is not preferred... which surprised a lot of us, apparently including 
the person who wrote those docs. :) )

> Are there any variants of the "open" commmand that
>allow location (drive and directory) of the file to be specified as
>well, for example, if I wanted to save the file as
>"D:\binaries\trash.gif" instead of the default location? 

As a matter of fact, the standard open() will handle that just fine -- 
it accepts a pathname, rather than just a filename, so you can feed it 
an absolute path like your example or a relative path (e.g., 
subdir\trash.gif or  ..\siblingdir\trash.gif) and it'll be perfectly 
happy.  The one catch is that, on Windows, the directory separator 
conflicts with the escape character, '\'.  So when typing path literals, 
be sure to either always use double backslashes ( 
"d:\\binaries\\trash.gif" ) or 'raw' strings ( r"d:\binaries\trash.gif" 
) so that your \trash doesnt become [tab]rash.  Or better yet, use 
os.path.join() (and the other os.path functions) to construct your paths.

Jeff Shannon
Credit International

More information about the Python-list mailing list