我有一个这样的数据集:
from dataclasses import dataclass, field
from typing import List
@dataclass
class stats:
target_list: List[None] = field(default_factory=list)
当我试图比较列表的内容时,如下所示:
if stats.target_list == None:
pass
我得到AttributeError:输入object 'stats‘没有属性'target_list’
我怎样才能解决这个问题?谢谢
关于课堂的一个蹩脚的问题:
class class1:
def __init__(self):
self = []
def insert1(self,x):
self.append(x) /// the object is a list in which x to be appended
a = class1()
a.insert1(5)
我得到: AttributeError:'class1‘对象没有属性'append’
我做错了什么?
我想在生成器和列表上运行嵌套循环。在循环中,我想访问每个元素的属性。
我发现了类似的关于遍历对象属性的代码问题,但是我无法解决我正在处理的问题。
下面是我的代码工作:
gen = api.search_submissions() # gen is generator of submissions
f_list = ['id','title']
sub_dict = {
'id':[],
'title':[]
}
for sub in gen:
for name in f_list:
s
我正在处理一个数据集,并希望创建一个名为“text”的特定列的所有值的textblob。我尝试了以下方法:
xp = positive.select("text").collect().map(_(0)).toList
#positive is the dataframes name, 'text' is the column name
xp = " ".join(positive['text])
到目前为止,这些方法都没有对我有效,并返回错误。
'list' object has no attribute 'ma
我用Python编写了一个正则表达式来获取字符串中的数字。但是,当我运行match.group()时,它说对象list没有属性group。我做错了什么?我输入的代码粘贴到终端,以及终端的响应。谢谢。
>>> #import regex library
... import re
>>>
>>> #use a regex to just get the numbers -- not the rest of the string
... matcht = re.findall(r'\d', dwtunl)
>>&g
谁能告诉我我哪里做错了?我正在用Python 3.x编写一个使用循环的程序,但是当我执行程序时,我得到了一个回溯错误:
13的倍数是195,因子如下回溯(最近一次调用):文件“C:/Users/Darlene/Desktop/第4章/Program4_2.py”,第19行。append(J) AttributeError:'dict‘对象没有属性'append’
这是我输入的代码:
def main():
for i in reversed(list(range(100,201))):
if i%13==0:
print("multipl
当我写这段代码lst=list(map(int,input().split().strip()))的时候,我得到了一个AttributeError 'list' object has no attribute strip
但是,当我删除strip()方法时,它可以正常工作。我的问题是list对象也没有split属性。那么,在这种情况下,(lst=list(map(int,input().split()))为什么没有给出任何错误,为什么在strip()方法的情况下会给出错误?
大家好,
我开始用Biopython编程,我想知道如何从具有所有特征坐标的基因组GenBank文件(*.gb)中提取基因序列和蛋白质标识符。
我的想法是创建一个包含蛋白质标识符、基因坐标和基因序列的文本文件。
如果你有任何想法,我将不胜感激。
到目前为止,我已经尝试过了:
for seq_record in seq_record.features:
if seq_record.type == 'CDS':
x=seq_record.qualifiers['protein_id']
i=seq_record.location.
我创建了这样一个属性对象:
a=property()
但当我跑的时候
list(a.__dict__)
它提出了一个例外:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute '__dict__'
那么,我的问题是如何查看“属性对象”的属性?不要使用dir(),因为我不想看到继承自其超类的属性。
我在python中的类中使用list有一个问题。下面是我的代码:
class Residues:
def setdata(self, name):
self.name = name
self.atoms = list()
a = atom
C = Residues()
C.atoms.append(a)
就像这样。我收到一个错误,说:
AttributeError: Residues instance has no attribute 'atoms'
因此,我尝试用以下代码将滚动条插入到我的窗口:
scrollbar= Scrollbar(root)#root is my window
list = [1,2,3,4,5]
for element in list:
scrollbar.insert(END, element)
scrollbar.pack(side="left")
但我试图用的那个属性不管用.我发现了一个错误:
AttributeError: 'Scrollbar' object has no attribute 'insert'
有人能帮帮我吗我不想
我一直试图把一些清单写到工作簿上的某个工作表上,但没有运气。我的代码是:
import xlwings as xw
from xlwings import Range
from xlwings import Book
wkb = xw.Book('Master_v3.xlsm')
sht = wkb.sheets['Control']
sht.Range('A1').value = some_list
这给了我一个错误:
*** AttributeError: 'Sheet' object has no attribute
我试图解析一个XML文档,以便只获取标记中的文本,但是当我测试-打印节点时,它只显示方括号,这意味着我的命令print(rede.text)返回"AttributeError:'list‘object没有属性' text '“。为什么XML内容存储为list对象,以及我如何访问标记中的文本?
import os
from xml.etree import ElementTree
file_name = '19008-data.xml'
full_file = os.path.abspath(os.path.join('WP19_Proto
我有一个实体列表,并希望使用实体键链接到单个实体的更多详细信息。
class RouteDetails(ndb.Model):
"""Get list of routes from Datastore """
RouteName = ndb.StringProperty()
@classmethod
def query_routes(cls):
return cls.query().order(-cls.RouteName)
class RoutesPage(webapp2.RequestHa
(编辑:我知道在Django中有一个完全不同的特性叫做“代理模型”。该特性对我没有帮助,因为我需要能够向UserProfile添加字段。)
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='profile')
def __getattr__(self, name, *args):
if
我不能让这个Python赋值像我期望的那样工作。到目前为止,我得到的所有解释对我来说都没有意义。
代码:
class attribute: #Mandatory may not be changed
def __init__(self,Input_1,Input_2):
self.info_1= Input_1
self.info_2= Input_2
def Lister(List1,List2): #Mandatory Function may not be removed
List= []
for x in List1: