>>>>> a = "my file number" >>>>> a.replace(' ', '\\ ') >> 'my\\ file\\ number' > > What if a has more than 1 space between words? Then I think this would > be a safer way. > >>>> print "\\ ".join("my file number".split()) > my\ file\ number
If those spaces are in the actual filename, you'll want to keep them, hence you'll need to escape those extra spaces as well. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor