Python path and append

Matthew Barnett mrabarnett at mrabarnett.plus.com
Tue Apr 19 19:36:52 EDT 2016


On 2016-04-19 23:38, Chris Angelico wrote:
> On Wed, Apr 20, 2016 at 8:29 AM, Seymore4Head
> <Seymore4Head at hotmail.invalid> wrote:
>>
>> handle = open("\\Winmx\New$\q.txt")
>> for line in handle:
>>     line=line.strip()
>>     print line
>>
>>
>> Traceback (most recent call last):
>>   File "\\Winmx\New$\add viewed.py", line 2, in <module>
>>     handle = open("\\Winmx\New$\q.txt")
>> IOError: [Errno 2] No such file or directory: '\\Winmx\\New$\\q.txt'
>>
>> What I would like to do is read a plain text file from a hidden
>> network drive and append a space and the * character to the end of
>> each line.
>
> Start with this:
>
> print("\\Winmx\New$\q.txt")
>
> If that doesn't do what you expect, it's possibly because you want to
> use a raw string literal to prevent the backslashes from being parsed.
>
> handle = open(r"\\Winmx\New$\q.txt")
>
> That might help you.
>
> (One clue that this is happening is that some of your backslashes got
> doubled in the error message.)
>
when printed out:

 >>> print "\\Winmx\New$\q.txt"
\Winmx\New$\q.txt

That's a file 2 directories down on the current drive.




More information about the Python-list mailing list