Reading files located on Windows-shares?

Alex Martelli aleax at
Mon Jan 28 07:11:28 EST 2002

"Thomas Weholt" <thomas at> wrote in message
news:Z1b58.67$ti7.170870784 at
> 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 ??

Same as when using C: mind the backslashes and the substitutions.


should work better: the leading r makes this literal into a rawstring (so
backslashes are taken literally) and the % operator formats string host
into the resulting filepath.  If the underlying C library supports UNC,
that's all you need.  Else, you'll need the win32all extensions.


More information about the Python-list mailing list