Access to shared directories

Jim Dennis jimd at vega.starshine.org
Tue Mar 19 12:50:51 EST 2002


In article <ae27bd174b.tim at worthy.demon.co.uk>, Tim Howarth wrote:
>
>In message <a6tg6u$69$1 at serv1.albacom.net>
>          "Fabrizio" <facelle at jumpy.it> wrote:

>> I just want to read a .txt file that I have in a shared directory on
>> another PC which is part of a WindowsNT/98 LAN.

>> What path should I use in order to read that file from my PC ?

>\\pcname\sharename\file.txt

	Warning: under Python you'll usually want to specify a
	"raw string" for MS Windows path names:

		r'\\machine\share\filename.ext'

	... otherwise Python's string parser will try to 
	interpret the backslash sequences like \n (newline) \r (return)
	\t (tab) \0xNN (hex character code) \0nnn (octal char. code)
	\\ (one "real" backwack) etc.

	This is an FAQ.  Newbies frequently have trouble with filename
	literals under various MS OSes.  Normal Python strings are 
	delimited with single or double quotes 'foo' or "foo."  However,
	"raw" strings are preceded by a letter r as in r'foo,' R"foo,"
	R'foo' or r"foo."  Newer versions of Python also support unicode
	literals (preceded by a U if I recall correctly).

	BTW: you cannot end a raw string literal with a single \  but
	you can "add" one to a string using the + operator.  Thus

		foo = r'\something\somewhere' + '\\'
		print foo

	... yields:

			\something\somewhere\

>___
> |im    ---- ARM Powered ----



More information about the Python-list mailing list