我不断收到错误消息
AttributeError: 'NoneType' object has no attribute 'something'
我所拥有的代码太长了,无法在此发布,但我想知道是否有人可以给出一般情况会导致这种情况的要点AttributeError,以及这NoneType应该是什么意思?
通常,您会收到代码出错的某个对象的名称,但由于它给了AttributeError我,我不确定如何缩小正在发生的事情,除了行号.
我试图将字典附加到 DataFrame 对象,但出现以下错误:
AttributeError:“DataFrame”对象没有属性“append”
据我所知,DataFrame确实有“append”方法。
代码片段:
df = pd.DataFrame(df).append(new_row, ignore_index=True)
我期待字典new_row被添加为新行。
我该如何修复它?
我有两个python模块:
a.py
import b
def hello():
  print "hello"
print "a.py"
print hello()
print b.hi()
b.py
import a
def hi():
  print "hi"
当我跑步时a.py,我得到:
AttributeError: 'module' object has no attribute 'hi'
错误是什么意思?我如何解决它?
如何__getattr__在模块上实现类的等价?
当调用模块静态定义的属性中不存在的函数时,我希望在该模块中创建一个类的实例,并在模块上的属性查找中使用与失败相同的名称调用其上的方法.
class A(object):
    def salutation(self, accusative):
        print "hello", accusative
# note this function is intentionally on the module, and not the class above
def __getattr__(mod, name):
    return getattr(A(), name)
if __name__ == "__main__":
    # i hope here to have my __getattr__ function above invoked, since
    # salutation does not exist in the current namespace
    salutation("world")
这使:
matt@stanley:~/Desktop$ python getattrmod.py 
Traceback (most recent call last):
  File "getattrmod.py", line 9, in <module>
    salutation("world")
NameError: name 'salutation' is not …在Python中我收到一个错误:
Exception:  (<type 'exceptions.AttributeError'>,
AttributeError("'str' object has no attribute 'read'",), <traceback object at 0x1543ab8>)
给出python代码:
def getEntries (self, sub):
    url = 'http://www.reddit.com/'
    if (sub != ''):
        url += 'r/' + sub
    request = urllib2.Request (url + 
        '.json', None, {'User-Agent' : 'Reddit desktop client by /user/RobinJ1995/'})
    response = urllib2.urlopen (request)
    jsonofabitch = response.read ()
    return json.load (jsonofabitch)['data']['children']
这个错误意味着什么,我做了什么导致它?
我正在尝试编写一个程序,将从网站上下载mp3然后将它们连接在一起,但每当我尝试下载文件时,我都会收到此错误:
Traceback (most recent call last):
File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 214, in <module> main()
File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 209, in main getMp3s()
File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 134, in getMp3s
raw_mp3.add = urllib.urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3")
AttributeError: 'module' object has no attribute 'urlretrieve'
导致此问题的线是
raw_mp3.add = urllib.urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3")
我在 AWS EMR 上使用 pyspark(4 个 r5.xlarge 作为 4 个工作线程,每个工作线程有 1 个执行程序和 4 个核心),并且我得到了AttributeError: Can't get attribute 'new_block' on <module 'pandas.core.internals.blocks'. 下面是引发此错误的代码片段:
search =  SearchEngine(db_file_dir = "/tmp/db")
conn = sqlite3.connect("/tmp/db/simple_db.sqlite")
pdf_ = pd.read_sql_query('''select  zipcode, lat, lng, 
                        bounds_west, bounds_east, bounds_north, bounds_south from 
                        simple_zipcode''',conn)
brd_pdf = spark.sparkContext.broadcast(pdf_) 
conn.close()
@udf('string')
def get_zip_b(lat, lng):
    pdf = brd_pdf.value 
    out = pdf[(np.array(pdf["bounds_north"]) >= lat) & 
              (np.array(pdf["bounds_south"]) <= lat) & 
              (np.array(pdf['bounds_west']) <= lng) & 
              (np.array(pdf['bounds_east']) >= lng) ]
    if len(out):
        min_index = np.argmin( (np.array(out["lat"]) - …我使用的是 conda 环境,Python 版本 3.9.7、pip 22.3.1、numpy 1.24.0、gluoncv 0.10.5.post0、mxnet 1.7.0.post2
from gluoncv import data, utils  给出错误:
C:\Users\std\anaconda3\envs\myenv\lib\site-packages\mxnet\numpy\utils.py:37: FutureWarning: In the future `np.bool` will be defined as the corresponding NumPy scalar.  (This may have returned Python scalars in past versions
  bool = onp.bool
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[1], line 3
      1 #import cv2
      2 #import os
----> 3 from gluoncv import data, utils #does not work
File ~\anaconda3\envs\myenv\lib\site-packages\gluoncv\__init__.py:16
     14 _found_mxnet = _found_pytorch = False
     15 try:
---> 16 …我试图通过pip3安装一个包,我收到了这个错误.我运行的每个pip/pip3命令都给我这个错误 -
alexg@hitbox:~$ pip3 -V
Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip import main
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in <module>
    @_call_aside
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside
    f(*args, **kwargs)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set
    dist.activate(replace=False)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate
    declare_namespace(pkg)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", …有一件事,我不明白.
为什么这样呢
import scipy # happens with several other modules, too. I took scipy as an example now...
matrix = scipy.sparse.coo_matrix(some_params)
产生这个错误:
AttributeError: 'module' object has no attribute 'sparse'
attributeerror ×10
python ×9
python-3.x ×3
pandas ×2
apache-spark ×1
dataframe ×1
getattr ×1
import ×1
module ×1
nonetype ×1
numpy ×1
pip ×1
pyspark ×1
python-2.7 ×1
python-3.5 ×1
urllib ×1
urllib2 ×1