Saving (unusual) linux filenames

AmFreak at web.de AmFreak at web.de
Tue Aug 31 17:45:13 EDT 2010


Thanks for all the nice answers!

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

The CSV module has something like that, but im using unicode and it  
doesn't work with that.



> Why is your impression that the null character is "dirty"?
>E.g. that's how find|xargs etc. usually work.
>Another alternative would be if you gaurantee that your varn's don't
> have commas then put the path last.  But that doesn't account for
> filenames containing newlines.
>Another alternative would be to wrap with some kind of serialization
> library. But really, what's so dirty about null?

I think i just prefer a little formated file instead of one loooong row :)




> A simple solution would be to save each line of data using JSON with the  
> json
> module:

>>> import json
>>>   path = "x,y,z"
>>> varA = 12
>>> varB = "abc"
>>> line = json.dumps([path, varA, varB])
>>> print line
["x,y,z", 12, "abc"]
>>> loadpathA, loadvarA, loadvarB = json.loads(line)
>>> print loadpathA
x,y,z
>>> print loadvarA
12
>>> print loadvarB
abc

Thanks, just tried it - so simple, but seems to work like a charm. Really  
aprecciated :D.



More information about the Python-list mailing list