python f""格式化字符串的时候报错too deeply 请问如何解决?
python f""格式化字符串的时候报错
f-string: expressions nested too deeply
tmp = "黄昏"s1 = f'{"music.search.SearchCgiService": {"method": "DoSearchForQQMusicDesktop","module": "music.search.SearchCgiService","param": {"num_per_page": 40,"page_num": 1,"query": {tmp},"search_type": 0}}}'
回答:
问题在于format匹配{}
,而你的字符串中本身也含有{ }
就会导致匹配出现问题。
python">tmp = "黄昏"s1 = ('{"music.search.SearchCgiService": {"method": "DoSearchForQQMusicDesktop","module": "music.search.SearchCgiService",'
'"param": {"num_per_page": 40,"page_num": 1,"query": %s,"search_type": 0}}}' % tmp)
这样用吧
回答:
f string 里 { }有特殊含义,如果 string 也有得画需要转义,{ 跟 } 分别需要用 {{ }} 代替。
以上是 python f""格式化字符串的时候报错too deeply 请问如何解决? 的全部内容, 来源链接: utcz.com/p/939114.html