0

我正在使用 Python SQLAlchemy cx_Oracle。我正在存储这样的字符串

"1 Some Road\nSome Place\nSome City"

进入 db.Text 字段。但是在保存它之后,我得到的是:

 "1 Some RoadSome PlaceSome City"

那么,你知道谁吃了我的“\n”吗?请帮帮我

这是我在 Python 中定义模型的方式:

class Object(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    address = db.Column(db.Text(100))

这是我保存它的方法:

o = Object(address=""1 Some Road\nSome Place\nSome City")
db.session.add(o)
db.session.commit()

之后,当我拥有它时, o.address 是:

 "1 Some RoadSome PlaceSome City"

干杯

4

1 回答 1

0

尝试像这样插入你的字符串:

insert into table_name (column_name) values ('1 Some Road' || chr(10) || 'Some Place' || chr(10) || 'Some City');

chr(10) 表示 ASCII 表中编号为 10 的字符 - “新行”

于 2013-10-29T15:05:25.423 回答