By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

multiline repr (code generation)

P: n/a
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

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?

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


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':"""
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

Any helpful suggestions?



Dr. Rasmus H. Fogh Email: r.******
Dept. of Biochemistry, University of Cambridge,
80 Tennis Court Road, Cambridge CB2 1GA, UK. FAX (01223)766002
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.