Python path and append

Chris Angelico rosuav at gmail.com
Tue Apr 19 18:38:50 EDT 2016


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.)

ChrisA



More information about the Python-list mailing list