Saving (unusual) linux filenames

Grant Edwards invalid at invalid.invalid
Tue Aug 31 17:22:00 CEST 2010


On 2010-08-31, AmFreak at web.de <AmFreak at web.de> wrote:
> Hi,
>
> i have a script that reads and writes linux paths in a file. I save the  
> path (as unicode) with 2 other variables. I save them seperated by "," and  
> the "packets" by newlines. So my file looks like this:
> path1, var1A, var1B
> path2, var2A, var2B
> path3, var3A, var3B
> ....
>
> this works for "normal" paths but as soon as i have a path that does  
> include a "," it breaks. The problem now is that (afaik) linux allows  
> every char (aside from "/" and null) to be used in filenames. The only  
> solution i can think of is using null as a seperator, but there have to a  
> cleaner version ?

The normal thing to do is to escape the delimiter when it appears in
data.  There are lots of plenty of escaping standards to choose from,
and some of them (e.g. the one used for URLs) are already present
in various bits of Python's standard library.

-- 
Grant Edwards               grant.b.edwards        Yow! ... the HIGHWAY is
                                  at               made out of LIME JELLO and
                              gmail.com            my HONDA is a barbequeued
                                                   OYSTER!  Yum!



More information about the Python-list mailing list