Convert a multi-line string to a single-line string

I am using the Google App Engine and I need to put a multi-line string in the data store. Unfortunately, GAE does not allow this. I need this line to be multi-line, so is there a way to convert a multi-line line to one line and store it?

+3
source share
2 answers

You do not need a conversion:

google.appengine.ext.db.StringProperty (multi-line = true)

+7
source

Replace all newline characters with "\ n" and replace all "\" with "\\", as with string literals:

def encode(s):
    return s.replace("\\", "\\\\").replace("\n", "\\n")
def decode(s):
    return s.replace("\\\\", "\\").replace("\\n", "\n")
0
source

Source: https://habr.com/ru/post/1757053/


All Articles