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}}}'

阅读量:19

点赞量:0

问AI
问题在于format匹配"{}",而你的字符串中本身也含有"{ }" 就会导致匹配出现问题。 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) 这样用吧