[Tutor] string conversion according to the terminal

Evert Rol evert.rol at gmail.com
Thu Aug 12 12:19:12 CEST 2010


>>>>> 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.



More information about the Tutor mailing list