在我的代碼上有問題。 我得到這個AttributeError,我不知道爲什麼。 有人提供一點點洞察力,謝謝! 這是用python 3寫的, 我正在試圖製作一個圖表。AttributeError:'str'對象沒有屬性'readlines'
import sys
data = {}
def main():
filename = sys.argv[1]
parseFile(filename)
function()
def parseFile(fn):
print("Parsing", fn)
infile = open(fn, "r")
for line in infile:
line = line[:-1]
tokens = line.split()
print(tokens)
if line[0]=="#":
line.readline() #<-- this is my problem line
rsid = (tokens[0])
genotype = (tokens[3])
data[rsid] = genotype
infile.close()
main()
# This data file generated by 23andMe at: Wed Jan 26 05:37:08 2011
#
# Below is a text version of your data. Fields are TAB-separated
# Each line corresponds to a single SNP. For each SNP, we provide its identifier
# (an rsid or an internal id), its location on the reference human genome, and the
# genotype call oriented with respect to the plus strand on the human reference
# sequence. We are using reference human assembly build 36. Note that it is possible
# that data downloaded at different times may be different due to ongoing improvements
# in our ability to call genotypes. More information about these changes can be found at:
# https://www.23andme.com/you/download/revisions/
#
# More information on reference human assembly build 36:
# http://www.ncbi.nlm.nih.gov/projects/mapview/map_search.cgi?taxid=9606&build=36
#
# rsid chromosome position genotype
rs4477212 1 72017 AA
rs3094315 1 742429 AA
rs1799883 1 742429 AA
rs3131972 1 742584 GG
rs12124819 1 766409 AA
rs11240777 1 788822 GG
rs6681049 1 789870 CC
rs4970383 1 828418 CC
rs4475691 1 836671 CC
rs7537756 1 844113 AA
這是什麼語言?哪條線的確切錯誤是什麼?你有沒有試圖減少你的例子? – usr1234567 2014-10-01 05:48:05
ahhh。對不起。蟒蛇。錯誤是在line.readline() 我試圖減少我的例子,但不是最好的這樣做 – Cooper 2014-10-01 05:49:07
爲什麼你有line.readline()那裏?你的意圖是什麼? – user1269942 2014-10-01 05:58:01