How to work with directories and files with spaces

Michele Petrazzo michele.petrazzo at TOGLIunipex.it
Thu Apr 6 08:06:21 EDT 2006


s99999999s2003 at yahoo.com wrote:
> hi
> 
> I am working in unix and i have some directories names with spaces
> eg ABC DEF A
> how can i work effectively with spaces in directory/file names in
> python?

Like you can do with unix:

michele:~$ echo "Michele" > my\ name
michele:~$ python
Python 2.3.5 (#2, May  4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> open("my name")
<open file 'my name', mode 'r' at 0x401e3ba0>
 >>> import os
 >>> os.system("cat my\ name")
Michele
0
 >>> os.system("cat 'my name'")
Michele
0

Bye,
Michele :)



More information about the Python-list mailing list