我需要將字符串轉換爲ASCII碼。我正在使用python。 我做了如下:將字符串轉換爲ASCII碼
b1=[ord(x) for x in l1[i]]
這裏L1是linelist,L1 [i]是L1
的第i行,但我有錯誤,如:
Traceback (most recent call last):
File "./fastq_phred_filter.py", line 24, in ?
b1=[ord(x) for x in str(l1[i])]
IndexError: string index out of range
我試着
b1=[ord(x) for x in str(l1[i])]
但仍然無法正常工作。
順便說一句,我有一個長期的問題:我總是處理線列表中的行(或列表中的鍵),是我從列表中獲得的行,一個字符串?或者需要我首先將該行轉換爲字符串?
THX
編輯:代碼更大的塊:
l1= commands.getoutput('zcat '+fastqfile1)
l2= commands.getoutput('zcat '+fastqfile2)
f1=[]
f2=[]
for i in range(0,len(l1)):
if i % 4 == 3:
b1=[ord(x) for x in l1[i]]
ave1=sum(b1)/float(len(l1[i]))
b2=[ord(x) for x in str(l2[i])]
ave2=sum(b2)/float(len(l2[i]))
if (ave1 >= 20 and ave2>= 20):.............
請標示語言。我猜python,但我不能確定。 –
-1請使用標籤來指定您正在使用的語言。 –
抱歉,我正在使用python – user815408