这个错误是由于在代码的第42行中,response_text.index('~')没有找到'~'字符串,导致substring not found的错误。\n\n要解决这个问题,你可以在使用index()方法之前先检查字符串中是否包含'~'字符。可以使用'~' in response_text来检查。如果包含,再执行response_text.index('~')+1:response_text.index('~1')。\n\n你可以将代码修改为以下内容:\n\npython\nif '~' in response_text:\n response_text = response_text[response_text.index('~')+1:response_text.index('~1')]\n f.write("Data for {}: {} ".format(column_name, response_text))\nelse:\n f.write("Data for {}: {} ".format(column_name, "Substring not found"))\n\n\n这样,如果字符串中包含'~'字符,就会执行正确的操作,否则会写入一个提示信息。


原文地址: https://www.cveoy.top/t/topic/pZPw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录