gpt4 book ai didi

python - 属性错误: 'GzipFile' object has no attribute 'next'

转载 作者:行者123 更新时间:2023-11-30 22:38:57 25 4
gpt4 key购买 nike

我将非常感谢您的帮助。我从我的代码的这一部分中收到一条错误消息,如下所述,我想用它来通过 affymetrix 微阵列分析(原始数据链接是 https://www.ncbi.nlm.nih.gov/sites/GDSbrowser?acc=GDS1615 )阐明克罗恩病和溃疡性结肠炎条件下的差异表达基因。但是当我运行这段代码时:

import gzip
import numpy as np

"""
Read in a SOFT format data file. The following values can be exported:

GID : A list of gene identifiers of length d
SID : A list of sample identifiers of length n
STP : A list of sample descriptions of length d
X : A dxn array of gene expression values
"""

fname = "../Anchang Charles/GDS1615_full.soft.gz"
with gzip.open(fname) as fid:
SIF = {}
for line in fid:
if line.startswith(line, len("!dataset_table_begin")):
break
elif line.startswith(line, len("!subject_description")):
subset_description = line.split("=")[1].strip()
elif line.startswith(line, len("!subset_sample_id")):
subset_ids = [x.strip() for x in subset_ids]
for k in subset_ids:
SIF[k] = subset_description
#.next().split("\t")
SID = fid.next().split("\t")
I = [i for i,x in enumerate(SID) if x.startswith("GSM")]
SID = [SID[i] for i in I]
STP = [SIF[k] for k in SID]

我收到一条错误消息,内容为

回溯(最近一次调用最后一次):

文件“”,第 1 行,位于 runfile('C:/Users/Anchang Charles/new affymetrix.py', wdir='C:/Users/Anchang Charles')

文件“C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 866 行,在运行文件中 execfile(文件名,命名空间)

文件“C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 102 行,在 execfile 中 exec(编译(f.read(),文件名,'exec'),命名空间)

文件“C:/Users/Anchang Charles/new affymetrix.py”,第 1 行,位于 从 affymetrix 导入 X,GID,STP,SID,UC,CD

文件“C:\Users\Anchang Charles\affymetrix.py”,第 26 行,位于 SID = fid.next().split("\t")

属性错误:“GzipFile”对象没有属性“next”

最佳答案

在 Python 3 中,iterator.next() 已替换为 iterator.__next__(),但您应该使用内置 来调用它next 函数如下:

next(iterator)

所以尝试一下:

next(fid).split("\t")

PEP 3114 中了解更多相关信息

改变背后原因的关键:

The use of double underscores creates a separate namespace for names that are part of the Python language definition, so that programmers are free to create variables, attributes, and methods that start with letters, without fear of silently colliding with names that have a language-defined purpose. (Colliding with reserved keywords is still a concern, but at least this will immediately yield a syntax error.)

The naming of the next method on iterators is an exception to this convention. Code that nowhere contains an explicit call to a next method can nonetheless be silently affected by the presence of such a method. Therefore, this PEP proposes that iterators should have a __next__ method instead of a next method (with no change in semantics).

关于python - 属性错误: 'GzipFile' object has no attribute 'next' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43356922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com