[Tutor] White spaces in a path (from a string variable) and os.popen on Windows
Jerry Hill
malaclypse2 at gmail.com
Thu Mar 8 16:36:56 CET 2007
On 3/8/07, learner404 <learner404 at gmail.com> wrote:
> When I know exactly the path in advance I use a raw string r' ' and I add
> double quotes where necessary to avoid the white spaces syndrome. But I
> don't see how to do this "easily" when my path is a string variable given by
> my GUI (like C:\Documents and Settings\name\Mes documents)
You can just choose to always quote the directory name where it might
have spaces in it. For instance, change this line:
> result=os.popen("dir "+dirPath).read()
to this:
result=os.popen('dir "%s"' % dirPath).read()
That worked fine with all the directories I threw at it.
--
Jerry
More information about the Tutor
mailing list