标签: attributeerror

AttributeError:“NoneType”对象没有属性“add”

我收到以下错误

AttributeError: 'NoneType' object has no attribute 'add'
Run Code Online (Sandbox Code Playgroud)

当我尝试这个时。

not_yet_bought_set = set()
.
.
.
for value in set_dict.itervalues():
    for item in value:
        not_yet_bought_set = not_yet_bought_set.add(item)
Run Code Online (Sandbox Code Playgroud)

我不明白为什么会出现此错误,是因为我总是将 not_yet_bought_set 设为新的吗?我做这个是因为当我只做的时候

not_yet_bought_set.add(item)
Run Code Online (Sandbox Code Playgroud)

不会有所有值的所有项目。我不知道为什么。

值是集合和

not_yet_bought_set.union(value)
Run Code Online (Sandbox Code Playgroud)

也产生这个错误

谢谢你的帮助。

python set attributeerror

3
推荐指数
1
解决办法
2万
查看次数

Cmd 模块属性错误

我正在尝试使用 python 的 cmd 模块,并且在 python 3.2 中编译此代码时,我在网站中获得了此测试代码

import cmd
import os

class ShellEnabled(cmd.Cmd):

    last_output = ''

    def do_shell(self, line):
        "Run a shell command"
        print ("running shell command:", line)
        output = os.popen(line).read()
        print (output)
        self.last_output = output

    def do_echo(self, line):
        "Print the input, replacing '$out' with the output of the last shell command"
        # Obviously not robust
        print (line.replace('$out', self.last_output))

    def do_EOF(self, line):
        return True

if __name__ == '__main__':
    ShellEnabled().cmdloop()
Run Code Online (Sandbox Code Playgroud)

我收到 cmd 模块的此错误。

AttributeError: 'module' object has no attribute 'Cmd' …
Run Code Online (Sandbox Code Playgroud)

python cmd attributeerror

3
推荐指数
1
解决办法
7576
查看次数

Python AttributeError:类对象没有属性

当我尝试运行我正在编写的类的代码时,我得到了一个消息AttributeError,但我不确定为什么。具体错误如下:

    self.marker = self.markers[marker[1:]]
AttributeError: 'TTYFigureData' object has no attribute 'markers'
Run Code Online (Sandbox Code Playgroud)

这是我正在写的课程的一部分:

class TTYFigureData(object):
    """
    data container of TTYFigure
    """
    def __init__(
        self,
        x,                      # x values
        y,                      # y values
        marker          = "_.", # datum marker
        plot_slope      = True
        ):
        self.x          = x
        self.y          = y
        self.plot_slope = plot_slope
        self.set_marker(marker)
        self.markers = {
            "-" : u"None" ,
            "," : u"\u2219"
        }

    def set_marker(
        self,
        marker
        ):
        if marker in [None, "None", u"None", ""]:
            self.plot_slope = True
            self.marker …
Run Code Online (Sandbox Code Playgroud)

python attributes class attributeerror

3
推荐指数
1
解决办法
2万
查看次数

Python .__class__.__name__ 适用于一个类,但不适用于另一个类

如果我被认为非常愚蠢,我很抱歉,我对 python 比较陌生,我不知道我在这里做错了什么。

我有两个班级,我尝试使用以下命令获取两个班级的班级名称

*class*.__class__.__name__
Run Code Online (Sandbox Code Playgroud)

现在,正如我所说,这适用于一个类,但不适用于另一个类。

这些是我的课程:

class fb():
    val = 300
    mult = 2.0
    shsym = pygame.image.load('img/dummy2.png')
    value = 50
class a():
    occ = 0
    shsym = pygame.image.load('img/it/a/shsym.png')
    plsym = pygame.image.load('img/it/a/plsym.png')
    value = 100
    hesyms = [pygame.image.load('img/a/hesym0',pygame.image.load('img/dummy.png'))]
    coord = [(50, 300),(30, 435),(310, 350)]
Run Code Online (Sandbox Code Playgroud)

里面的变量可能并不重要,但由于我无法找出问题所在,所以我只包含了整个内容。

然后我定义它们

fob = fb()
ita = a()
Run Code Online (Sandbox Code Playgroud)

然后我将变量设置为定义的类之一

itemselect = fob
Run Code Online (Sandbox Code Playgroud)

最后,我尝试检查类的名称并查看它是否以“f”开头(看看它是否是一组项目的一部分)

if not itemselect.__class__.__name__.startswith("f"):
Run Code Online (Sandbox Code Playgroud)

在那一行我收到错误消息

Traceback (most recent call last):
  File "D:\Programmieren\Cola Atsume\main.py", line 283, in <module>
     if not itemselect.__class__.__name__.startswith("f"):
AttributeError: class fa has …
Run Code Online (Sandbox Code Playgroud)

python class attributeerror

3
推荐指数
1
解决办法
5579
查看次数

networkx 有向图属性错误 self._succ

上下文:我正在尝试运行另一位研究人员的代码 - 它描述了湾区道路网络的交通模型,该模型受地震危险的影响。我是 Python 的新手,因此非常感谢调试以下错误的一些帮助。

问题:当我尝试按照自述文件中的说明运行随文件提供的示例数据的代码时,出现以下错误。

DN0a226926:quick_traffic_model gitanjali$ python mahmodel_road_only.py
You are considering 2 ground-motion intensity maps.
You are considering 1743 different site locations.
You are considering 2 different damage maps (1 per ground-motion intensity map).
Traceback (most recent call last):
  File "mahmodel_road_only.py", line 288, in <module>
main()
  File "mahmodel_road_only.py", line 219, in main
  G = get_graph()
  File "mahmodel_road_only.py", line 157, in get_graph
  G = add_superdistrict_centroids(G)
  File "mahmodel_road_only.py", line 46, in add_superdistrict_centroids
  G.add_node(str(1000000 + i))
  File "/Library/Python/2.7/site-packages/networkx-2.0-py2.7.egg/networkx/classes/digraph.py", line …
Run Code Online (Sandbox Code Playgroud)

python directed-graph attributeerror networkx

3
推荐指数
1
解决办法
4418
查看次数

AttributeError: 'ContactUs' 对象没有属性 'model'

任何人都可以帮助我,我尝试在 python-django 上创建联系表单,当我尝试在数据库上进行迁移时,我收到错误“AttributeError: 'ContactUs' object has no attribute 'model'”

视图.py

from django.shortcuts import render
from .forms import ContactForm, ContactUs
from django.core.mail import EmailMessage
from django.shortcuts import redirect
from django.template.loader import get_template


def contact(request):
    form_class = ContactForm

    # new logic!
    if request.method == 'POST':
        form = form_class(data=request.POST)

        if form.is_valid():
            first_name = request.POST.get('first_name', '')
            last_name = request.POST.get('last_name', '')
            date = request.POST.get('date', '')
            month = request.POST.get('month', '')
            year = request.POST.get('year', '')
            sender = request.POST.get('sender', '')
            message = request.POST.get('message', '')
            licence = request.POST.get('licence', '') …
Run Code Online (Sandbox Code Playgroud)

python django attributeerror

3
推荐指数
1
解决办法
2719
查看次数

属性错误:列表对象没有属性“apply”

time_weight = list(100*np.exp(np.linspace(-1/divisor, -(num_steps-1)/divisor, num_steps))).apply(lambda x:int(x))
Run Code Online (Sandbox Code Playgroud)

当我尝试这样做时,我在 Python 3.7 中收到以下错误。

AttributeError:“列表”对象没有属性“应用”

有人能帮忙吗?

python numpy list attributeerror python-3.7

3
推荐指数
1
解决办法
2万
查看次数

AttributeError: 模块 'scipy.stats' 没有属性 'signaltonoise'

我正在使用下面的 scipy signaltonoise 函数是代码,但它返回一个错误。我也在github中搜索过这个,但找不到。你能帮忙吗。

import numpy as np
import cv2
import math
import os
import csv
from scipy import stats 
from PIL import Image
from skimage.color import rgb2gray
from multiprocessing import Pool
from skimage.feature import local_binary_pattern # Local Binary Pattern function
from scipy.stats import itemfreq # To calculate a normalized histogram
import scipy.stats as sp
from skimage.feature import hog
from scipy.ndimage.measurements import label
from scipy import signal as sg




def calc_snr(img):
    snr = stats.signaltonoise(img, axis=None)
    return snr


 snr = calc_snr(img)
Run Code Online (Sandbox Code Playgroud)

python numpy scipy attributeerror python-3.x

3
推荐指数
1
解决办法
3578
查看次数

AttributeError: 'str' 对象在 python 中没有属性 'seek'

运行以下代码时出现“AttributeError: 'str' object has no attribute 'seek'”。有人可以指出问题出在哪里吗?

import re
import os
import time

regex = ' \[GC \((?<jvmGcCause>.*?)\).+?(?<jvmGcRecycletime>\d+\.\d+) secs\]'
read_line = True

def follow(thefile):
    thefile.seek(0,os.SEEK_END)
    while True:
        lines = thefile.readline()
        if not lines:
            time.sleep(0.1)
            continue
        yield lines

if __name__ == '__main__':
    logfile = r"/gc.log"
    loglines = follow(logfile)
    for line in loglines:
        match = re.search(regex, line)
        if match:
            print('jvmGcCause: ' + +match.group(1))
            print('jvmGcRecycletime: ' + match.group(2))
Run Code Online (Sandbox Code Playgroud)

python attributes seek attributeerror

3
推荐指数
1
解决办法
4436
查看次数

AttributeError:模块“预处理器”没有属性“clean”

我正在尝试使用预处理器库来清理存储在 Pandas 数据框中的文本。我已经安装了最新版本(https://pypi.org/project/tweet-preprocessor/),但收到以下错误消息:

import preprocessor as p
#forming a separate feature for cleaned tweets
for i,v in enumerate(df['text']):
    df.loc[v,'text'] = p.clean(i)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-183-94e08e1aff33> in <module>
      1 #forming a separate feature for cleaned tweets
      2 for i,v in enumerate(df['text']):
----> 3     df.loc[v,'text'] = p.clean(i)

AttributeError: module 'preprocessor' has no attribute 'clean'
Run Code Online (Sandbox Code Playgroud)

python preprocessor attributeerror

3
推荐指数
1
解决办法
6559
查看次数