open filename with spaces in path

Gary Herron gherron at islandtraining.com
Tue May 6 19:02:34 EDT 2008


Michael Robertson wrote:
> I'm having trouble opening a file in linux, whose path has spaces in it.
>
> $ mkdir my\ test
> $ echo test > my\ test/test.txt
> $ python
>
> >>> open('./my test/test.txt')
> Exception

This works just fine for me.  No need to escape the spaces.

You haven't given us much to work with -- tell us what exception you 
get.    (Or just look at it carefully yourself.)   Whatever the problem 
is, I don't believe it has anything to do with the spaces.

Gary Herron


>
> >>> open('./my\\ test/test.txt')
> Exception

> but yet...
>
> >>> import os
> >>> os.chdir('./my test')
> >>> open('./test')
>
> works just fine.
> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list