小编use*_*873的帖子

在函数中以TypeError开头

这是代码:

    def readFasta(filename):
        """ Reads a sequence in Fasta format """
        fp = open(filename, 'rb')
        header = ""
        seq = ""
        while True:
            line = fp.readline()
            if (line == ""):
                break
            if (line.startswith('>')):
                header = line[1:].strip()
            else:
                seq = fp.read().replace('\n','')
                seq = seq.replace('\r','')          # for windows
                break
        fp.close()
        return (header, seq)

    FASTAsequence = readFasta("MusChr01.fa")
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

TypeError: startswith first arg must be bytes or a tuple of bytes, not str
Run Code Online (Sandbox Code Playgroud)

但startswith根据文档,第一个参数应该是一个字符串......那么发生了什么?

我假设我使用的是至少Python 3,因为我使用的是最新版本的LiClipse.

python python-3.x

39
推荐指数
1
解决办法
3万
查看次数

包含头文件会导致类型冲突

所以我在头文件中有这个结构,称之为 h1.h

typedef struct{
    int a;
    int b;
    special_t test;
} randomDataType
Run Code Online (Sandbox Code Playgroud)

所以我包含了包含special_t 声明的头文件。两个头文件中的函数都没有命名相同,而且我不知道循环依赖如何发挥作用,因为第二个头文件中声明的函数只能通过 h1.h 中声明的函数访问

然而,我对另一个标头中的所有内容都有“先前声明_ _”错误。为什么是这样?

c

1
推荐指数
1
解决办法
3806
查看次数

标签 统计

c ×1

python ×1

python-3.x ×1