【发布时间】:2014-11-25 21:45:34
【问题描述】:
我的代码有问题。 我收到了这个 AttributeError ,我不知道为什么。 请有人提供一点见解,谢谢!!! 这是用python 3编写的, 我正在尝试制作图表。
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
【问题讨论】:
-
那是什么语言?哪一行的确切错误是什么?你试过减少你的例子吗?
-
啊。对不起。 Python。错误在 line.readline() 我试图减少我的例子,但不是最好的这样做
-
为什么你有 line.readline() 那里?你的意图是什么?
-
我也在尝试这个 print(tokens) line = line.readline()[1:] rsid = (tokens[0]) 但无济于事
-
你能举一个你正在阅读的文件中的一些行的例子吗?
标签: string python-3.x attributeerror