open filename with spaces in path

Micah Elliott mde at MicahElliott.com
Tue May 6 19:00:13 EDT 2008


On 2008-05-06 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

That's funny.  These exact steps work fine for me on Linux, with
Python 2.5.2, and even 1.5.2.

Does 'os.path.normpath' have anything interesting to say about
what you're passing it?

> but yet...
>
> >>> import os
> >>> os.chdir('./my test')
> >>> open('./test')
>
> works just fine.

How doctored up is this example?  In the above ./test should not
actually exist.  Did the chdir actually work?  Or did you remove
the .txt?

-- 
Micah Elliott | mde at MicahElliott.com | http://MicahElliott.blogspot.com



More information about the Python-list mailing list