/ Traceback最近一次通话:IndexError:列表索引超出范围 空输入非空输入可能的解决方案

问题描述

跟踪(最近一次通话最近):IndexError:列表索引超出范围

from sys import argv,exit
import csv
import sys
    
def main ():
    if len(sys.argv) < 3:
        print("Usage: python dna.py data.csv sequence.txt")
        exit(1)
    # open csv_file contain the database 
    with open(sys.argv[1]) as csvfile:
        r = csv.reader(csvfile)
        # open txt_file contain the DNA sequence 
        with open(sys.argv[2]) as txtfile:
            x = txtfile.read()
            y = [v for v in [max_substring(x,seq) for seq in next(r)[1:]] if v >= 0]
        print_match(r,y)

# count the maximum substring           
def max_substring(x,sub_str):
    if not x and not sub_str:
        return -1
    sub_repeat = len(x)*[0]
    for s in range(len(x) - len(sub_str),-1,-1): 
        a = s + len(sub_str)
        if x[s: a] == sub_str:
            b = len(x) - 1
            c = 1 + sub_repeat[a - 1]
            sub_repeat[s] = 1 if  a > b else c
    return max(sub_repeat)

# Make some assertions
assert max_substring('abcabbcab','ab') == 1
assert max_substring('','') == -1
assert max_substring('abcabbcab','abcabbcab') == 1
    
# print the result
def print_match(r,y):
    for line in r:
        if [int(val) for val in line[1:]] == y:
            print(line[0]) 
            return
    print("No match")
# run the functions & class
if __name__ == "__main__" :
    main()

跟踪(最近一次通话最近):IndexError:列表索引超出范围

[新输出错误 [1]:https://i.stack.imgur.com/lKKD8.png

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)