repr(string)

David C. Ullrich dullrich at sprynet.com
Thu Jul 24 12:26:12 EDT 2008


In article <g6a6u2$kfk$03$1 at news.t-online.com>,
 Peter Otten <__peter__ at web.de> wrote:

> David C. Ullrich wrote:
> 
> > In article <mailman.561.1216843813.922.python-list at python.org>,
> >  Fredrik Lundh <fredrik at pythonware.com> wrote:
> > 
> >> David C. Ullrich wrote:
> >> 
> >> > I've been saving data in a file with one line per field.
> >> > Now some of the fields may become multi-line strings...
> >> > 
> >> > I was about to start escaping and unescaping linefeeds
> >> > by hand, when I realized that repr() and eval() should
> >> > do. Hence the question: If s is a string, is repr(s)
> >> > guaranteed not to contain line breaks?
> >> 
> >> yes.
> >> 
> >> just keep in mind that using eval() on untrusted data isn't a very good
> >> idea.
> > 
> > Right. This data comes from me, gets put into a file and then
> > read by me. Someone _could_ corrupt that file, but someone who
> > could do that could more easily just throw the machine out
> > the window...
> 
> You could also use a csv file with a single row.

Excellent suggestion. I have a different point of view on all
this than most of you guys (see reply to F). From my curious
point of view csv was no fun anymore when csvlib got added to Python...

> Peter

-- 
David C. Ullrich



More information about the Python-list mailing list