私は文字列を持っています:
f = open("file.txt", r)
message = f.read()
print message
>>> "To: email\ntitle: add title here\nDescription: whatever here\n"
次のようにして文字列を分割できます。
f_email, f_title, f_description, blank = message.split('\n')
しかし、次のようなメッセージがあると問題が発生します。
"To: email\ntitle: add title here\nDescription: first line\nSecond line\nthirdline\n"
文字列を分割すると、説明も分割されます。私が試してみました:
f_email, f_title, f_description, blank = message.split('\n',4)
しかし、4つ以上の\ nを分割しているため、明らかにValueErrorが返されます。
助言がありますか?