标签: attributeerror

Python'AttributeError:'function'对象没有属性'min''

首先,对这两个问题的明显程度表示道歉; 我对此非常陌生,并且不知道我在做什么.

我正在尝试编写一些内容来将样条插值的Scipy函数应用于值数组.我的代码目前看起来像这样:

import numpy as np
import scipy as sp
from scipy.interpolate import interp1d

x=var
x1 = ([0.1,0.3,0.4])
y1 = [0.2,0.5,0.6]

new_length = 25
new_x = np.linspace(x.min(), x.max(), new_length)
new_y = sp.interpolate.interp1d(x, y, kind='cubic')(new_x)
Run Code Online (Sandbox Code Playgroud)

但当它到达线

new_x = np.linspace(x.min(), x.max(), new_length)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

AttributeError: 'function' object has no attribute 'min'
Run Code Online (Sandbox Code Playgroud)

到目前为止,谷歌搜索等没有发现任何我理解的内容.这是什么意思,我该如何解决?

第二个问题:如何一次输入多行代码?目前,如果我尝试复制整个内容然后将其粘贴到PyLab中,它只输入我的代码的顶行,所以我必须一次将整个内容粘贴到一行中.我怎么绕这个?

python attributes numpy attributeerror

12
推荐指数
2
解决办法
7万
查看次数

Python3 AttributeError:'list'对象没有属性'clear'

我正在使用Python 3.2.3版的Linux机器上工作.每当我尝试这样做时,list.clear()我都会遇到异常

>>> l = [1, 2, 3, 4, 5, 6, 7]
>>> l.clear()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'clear'
Run Code Online (Sandbox Code Playgroud)

同时在我的Mac上使用Python 3.4.3,相同的代码运行顺畅.它可能是由于Python版本之间的差异还是我缺少的东西?

python list attributeerror python-3.x python-3.2

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

Python属性错误:类型对象'_socketobject'没有属性'gethostbyname'

我想在我的程序中这样做:

dest = socket.gethostbyname(host)
Run Code Online (Sandbox Code Playgroud)

我已经包括这条线:

from socket import * 
Run Code Online (Sandbox Code Playgroud)

在文件的开头.

我收到此错误:

AttributeError:类型对象'_socketobject'没有属性'gethostbyname'

我正在运行Vista 64bit.我的操作系统有问题吗?我拒绝了我的防火墙和一切.

python attributeerror gethostbyname

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

获取AttributeError:<class>没有属性<method>

我在模块mod1中的类中创建一个方法,并按如下方式调用它:

class blahblah:
   def foobar(self, bvar, **dvar)
       ////
       return dvar
Run Code Online (Sandbox Code Playgroud)

并将其称为:

obj1 = mod1.blahblah()
dvar1 = obj1.foobar(True, **somedictionary)
Run Code Online (Sandbox Code Playgroud)

它扔了一个 Attribute error: blahblah has no attribute named foobar

你能帮帮我吗?提前致谢

python attributeerror

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

AttributeError:'NoneType'对象没有属性'endswith'

我目前正在开发一个更新网页的Python脚本.但是运行主脚本会产生以下错误:

<res status='-1'><error message="'NoneType' object has no attribute 'endswith'"><![CDATA[
Traceback (most recent call last):
  File "/path/to/file/ws_config.py", line XXXX, in Run
    tests = TestList().tests
  File "/path/to/file/ws_config.py", line XXXX, in __init__
    UpdateTestGroup(None),
  File "/path/to/file/ws_config.py", line XXXX, in __init__
    test = CT.CurlTest(settings),
  File "/path/to/file/config_tests.py", line XXXX, in __init__
    self.params.path = os.path.join('/', os.path.join(params.dir, params.file))
  File "/usr/lib/python2.6/posixpath.py", line 67, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
Run Code Online (Sandbox Code Playgroud)

我不能通过任何代码,因为太长了.我想要了解的是错误的位置或代码的哪一部分触发了AttributeError.你能帮我么???

python attributeerror nonetype ends-with

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

__del__上的Python attributeError

我有一个python类对象,我想分配一个类变量的值

class Groupclass(Workerclass):
    """worker class"""
    count = 0

    def __init__(self):
        """initialize time"""
        Groupclass.count += 1
        self.membercount = 0;
        self.members = []

    def __del__(self):
        """delte a worker data"""
        Groupclass.count -= 1


if __name__ == "__main__":
    group1 = Groupclass()
Run Code Online (Sandbox Code Playgroud)

此执行结果是正确的,但有一条错误消息说:

Exception AttributeError: "'NoneType' object has no attribute 'count'" in <bound method Groupclass.__del__ of <__main__.Groupclass instance at 0x00BA6710>> ignored
Run Code Online (Sandbox Code Playgroud)

谁能告诉我,我做错了什么?

python class del attributeerror

11
推荐指数
1
解决办法
8189
查看次数

AttributeError:LinearRegression对象没有属性'coef_'

我一直在尝试通过线性回归来拟合这些数据,遵循bigdataexaminer的教程.到目前为止,一切都很好.我从sklearn导入了LinearRegression,并且很好地打印了系数.这是我尝试从控制台获取系数之前的代码.

import numpy as np
import pandas as pd
import scipy.stats as stats
import matplotlib.pyplot as plt
import sklearn
from sklearn.datasets import load_boston
from sklearn.linear_model import LinearRegression

boston = load_boston()
bos = pd.DataFrame(boston.data)
bos.columns = boston.feature_names
bos['PRICE'] = boston.target

X = bos.drop('PRICE', axis = 1)

lm = LinearRegression()
Run Code Online (Sandbox Code Playgroud)

完成所有这些设置后,我运行以下命令,并返回正确的输出:

In [68]: print('Number of coefficients:', len(lm.coef_)

Number of coefficients: 13
Run Code Online (Sandbox Code Playgroud)

但是,现在如果我再次尝试打印同一行,或者使用'lm.coef_',它告诉我coef_不是LinearRegression的属性,就在我刚刚成功使用它之后,我没有触及任何在我再次尝试之前的代码.

In [70]: print('Number of coefficients:', len(lm.coef_))

Traceback (most recent call last):

 File "<ipython-input-70-5ad192630df3>", line 1, in <module>
print('Number of coefficients:', …
Run Code Online (Sandbox Code Playgroud)

python linear-regression attributeerror python-3.x scikit-learn

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

使用os.scandir()引发AttributeError:__ exit__

AttributeError当我使用python文档中的示例代码(这里)时引发了一个问题.示例代码如下:

with os.scandir(path) as it:
    for entry in it:
        if not entry.name.startswith('.') and entry.is_file():
            print(entry.name)
Run Code Online (Sandbox Code Playgroud)

结果是AttributeError:

D:\Programming>test.py
Traceback (most recent call last):
  File "D:\Programming\test.py", line 3, in <module>
    with os.scandir() as it:
AttributeError: __exit__
Run Code Online (Sandbox Code Playgroud)

虽然,分配os.scandir()给变量工作正常.有人能告诉我我错过了什么吗?

python attributeerror scandir python-3.x

11
推荐指数
1
解决办法
3232
查看次数

Matplotlib 图“.supxlabel”不起作用

我正在尝试为我的条件六边形分箱图设置图形标签,但是当我运行此代码时,我收到 Attribute Error: 'Figure'object has no attribute 'supxlabel'。任何有关此问题的帮助将不胜感激。

zip_codes = [98188, 98105, 98108, 98126]

def hexbin_zips(ax, zipcode):
    kc_tax_zip = kc_tax_stripped.loc[kc_tax_stripped['ZipCode'] == zipcode]
    out = ax.hexbin(kc_tax_zip['SqFtTotLiving'], kc_tax_zip['TaxAssessedValue'], gridsize=30)
    return out

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(12, 10), sharex='col', sharey='row')
axes = [ax1, ax2, ax3, ax4]

for n in range(4):
    hexbin_zips(axes[n], zip_codes[n])
    axes[n].set_title(str(zip_codes[n]))

fig.supxlabel('Total Living Space in Square Feet', fontsize=16.)
fig.supylabel('Tax-Assessed Value', fontsize=16.)
Run Code Online (Sandbox Code Playgroud)

python plot matplotlib attributeerror

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

numpy load引发"AttributeError:'module'对象没有属性'expr'"

我试着跑

#!/usr/bin/env python

import os
from numpy import *

b= ones((3, 3))  
print b  
save('fff',  b)  
a = load('fff.npy')  
print a.shape  
print 'fertig'
Run Code Online (Sandbox Code Playgroud)

但它引起了:

Traceback (most recent call last):  
  File "savetest.py", line 9, in <module>  
    a = load('fff.npy')  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/io.py", line 195, in load  
    return format.read_array(fid)  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/format.py", line 353, in read_array  
    shape, fortran_order, dtype = read_array_header_1_0(fp)  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/format.py", line 250, in   read_array_header_1_0  
    d = safe_eval(header)  
  File "/usr/lib/python2.6/dist-packages/numpy/lib/utils.py", line 840, in safe_eval  
    ast = compiler.parse(source, "eval")  
  File "/usr/lib/python2.6/compiler/transformer.py", line 53, …
Run Code Online (Sandbox Code Playgroud)

arrays load numpy attributeerror

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