【发布时间】:2017-01-31 05:56:58
【问题描述】:
已找到此链接:
How can I print literal curly-brace characters in python string and also use .format on it?
由于我在这个字符串中有一些疯狂的字符,我并没有把我带到我需要去的地方。我需要能够保留外部大括号(在以 ':9502...' 开头的行中),同时能够格式化 {0}。
try:
filtered_df['Path'] = \
filtered_df['Path'].apply(lambda x: '<a href="http://'
+ host
+ ':9502/analytic/saw.dll?catalog#{"location"%3A"{0}"}" target="_blank">{1}</a>'.format(urllib.quote(x, safe=''), x))
如您所见,我正在尝试将 pandas 数据框中的一些列值简单地更改为 html 链接。问题是目标链接所需的格式(下面详述的部分):
catalog#{"location"%3A"{0}"}" target="_blank">{1}</a>'.format(urllib.quote(x, safe=''), x))
我只想说这太疯狂了,这就是它必须看起来才能到达我需要去的地方。问题是它不允许应用程序按照编写的方式执行,所以问题是,至少我猜是我需要对那些大括号和一些引号做些什么?
【问题讨论】:
标签: python string pandas curly-braces html-escape-characters