Reading files located on Windows-shares?

David Robinow drobinow at yahoo.com
Mon Jan 28 13:26:56 EST 2002


"Thomas Weholt" <thomas at gatsoft.no> wrote in message news:<Z1b58.67$ti7.170870784 at news.telia.no>...
> I need to read a specific file located on several shared folders on specific
> machines on a Windows-based network.
> 
> I got a list of machines, which have all shared the folder 'data':
> 
> hosts = ['foo1','foo2','bar1','bar2']
> 
> In Windows Explorer I'd access these folders by just typing
> \\machinename\sharedfolder in the location-field.
> 
> Doing something like :
> 
> for host in hosts:
>     print open('\\%s\\data\config.dat', 'r').read()
> 
> Doesn't work. How can I work with Windows-shared folders using Python ??
   You need to escape backslashes.  Try
       print open('\\\\%s\\data\\config.dat', 'r').read()
   or
       print open('//%s/data/config.dat', 'r').read()



More information about the Python-list mailing list