擅长:python、mysql、java
<p>问题不是因为读了1000行,而是因为有些行没有数据</p>
<p><strong>即:</strong></p>
<pre><code>st="""
...:
...:
...: asd
...: """
print st
'\n\n\nasd\n'
lst=st.split("\n")
print lst
['', '', '', 'asd', '']
print lst[1][-1]
-
IndexError Traceback (most recent call last)
<ipython-input-65-82ba25ef865c> in <module>()
> 1 print lst[1][-1]
IndexError: string index out of range
</code></pre>
<p>我解决这个问题的方法是三元表达式</p>
<p><strong>代码:</strong></p>
<pre><code>print lst[1][-1] if len(lst[1])>0 else "None"
</code></pre>
<p><strong>在您的情况下:</strong></p>
<pre><code>genome = genome + k_mers_parsed[i][-1] if len(k_mers_parsed[i])>0 else " "
</code></pre>