Can';t在Python字符串格式中转义和解析字符

Can';t在Python字符串格式中转义和解析字符,python,string,pandas,curly-braces,html-escape-characters,Python,String,Pandas,Curly Braces,Html Escape Characters,已找到此链接: 我还没有到达我需要去的地方,因为我在这个字符串中有一些疯狂的字符。我需要能够保留外部的花括号(在以“:9502…”开头的行中),同时能够格式化{0} try: filtered_df['Path'] = \ filtered_df['Path'].apply(lambda x: '<a href="http://' + host

已找到此链接:

我还没有到达我需要去的地方,因为我在这个字符串中有一些疯狂的字符。我需要能够保留外部的花括号(在以“: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))
试试看:
过滤的_df['Path']=\
已筛选的_df['Path'].apply(lambda x:''.format(urllib.quote(x,safe=''),x))
如您所见,我试图简单地将pandas数据框中的一些列值更改为html链接。问题是目标链接所需的格式(下面详述的部分):

catalog{“location”%3A“{0}”target=“_blank”>{1}”。格式(urllib.quote(x,safe=”),x))

我只想说它非常疯狂,这就是它要达到我需要去的地方的样子。问题是它不允许应用程序按编写的方式执行,所以问题是,至少我猜,我需要对那些花括号和一些引号做些什么?

你可以通过将它们加倍来避免花括号。

'outside{{inside {0}}}'.format('stuff')

'outsid{inside stuff}'

你可以通过将花括号对折来摆脱它们

'outside{{inside {0}}}'.format('stuff')

'outsid{inside stuff}'