Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > multiline repr (code generation)

Reply
Thread Tools

multiline repr (code generation)

 
 
Rasmus Fogh
Guest
Posts: n/a
 
      09-03-2003
Dear All,

I need a way of writing strings or arbitrary Python code that will

a) allow the strings to be read again unchanged (like repr)
b) write multiline strings as multiline strings instead of escaping the
\n's.

A repr function that output triple-quoted strings with explicit
(non-escaped) linebreaks would be perfect.

Failing that, what is the simplest way to get close to the goal?

================================================== =====================

Details:

I am working on an automatic code generation project, using Python scripts
to generate Python code.

As part of that I need to:

1) read Python code from a non-Python external file (more precisely, from
storage in a UML editing tool). I do control the strings, but they should
be legible and correct as Python code.

2) write the string to file, in such as way that they will come back
unchanged when the file is imported, e.g.
codeInfo = {'dataConstraint':"""
my
multiline
code string
"""}

3) write the string out to a file as actual executable python code.

4) be able to handle any valid Python code in the string, except for
embedded multiline strings.

5) Have the strings appear as multiline in my various files. A single
400-character line with embedded '\n's may be correct Python code, but it
is so unreadable that I would prefer to avoid it.

If I cannot have all my requirements, I would like the best possible
compromise.

Any helpful suggestions?

Thanks,

Rasmus

---------------------------------------------------------------------------
Dr. Rasmus H. Fogh Email: http://www.velocityreviews.com/forums/(E-Mail Removed)
Dept. of Biochemistry, University of Cambridge,
80 Tennis Court Road, Cambridge CB2 1GA, UK. FAX (01223)766002


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to define a variable to hold a multiline text input in perl from html multiline textbox dale zhang Perl Misc 8 11-30-2004 06:53 AM
Triple quoted repr Edward C. Jones Python 1 06-03-2004 06:44 PM
print / str / repr Nikolai Kirsebom Python 1 05-18-2004 05:11 PM
str() or repr() tcronj Python 0 02-12-2004 06:14 PM
avoiding recursion in repr? David C. Fox Python 2 12-04-2003 06:55 AM



Advertisments