我刚开始使用.loc,但每次我尝试使用它时,它都会返回'TypeError:'DataFrame‘object is not callable’。
例如,我不能让这个简单的代码(在pokemon API上使用)工作:
print(df.loc(df('Attack') > 175))
TypeError: 'DataFrame' object is not callable
有没有人能帮帮我,为什么它不能工作,真的很困扰我?
我正在尝试验证和格式化一个类变量。这个类扩展了一个以ABCMeta作为其__metaclass__的类,而我还不能实例化我的子类。因此,当我运行下面的代码时,它打印属性对象,而不是我想要的输出,这我理解为什么。但是我该怎么做呢?
from abc import ABCMeta, abstractproperty
class RuleBase(object):
__metaclass__ = ABCMeta
id = None
id = abstractproperty(id)
@property
def format_id(self):
我定义了我的单例元类如下:
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
然后,我定义了另一个类,作为实现的接口:
class ClientBase(metaclass
当我在线阅读代码时,我遇到了以下使用抽象类的情况
from abc import abstractmethod,ABCMeta
class Generator(object,metaclass=ABCMeta):
@abstractmethod
def generate(self):
raise NotImplementedError("method not implemented")
generator=Generator()
generator.generate()
如预期的那样,返回以下错误:
TypeError: Can't in
如果类指定了元类,那么从ABC继承的正确方式是什么?
简单的尝试
class KindMeta(type):
...
class Kind(ABC, metaclass=KindMeta):
...
导致TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
在KindMeta中继承ABCMeta似乎是错误的,因为这个mcs也用于创建非抽象类。
创建从KindMeta继承
ABC类是用来检查对象类型的,因此不能实例化。事实上:
basestring()
抛出:
TypeError: The basestring type cannot be instantiated
但是,ABC编号不会发生这种情况:
from numbers import number
number()
它不抛出任何异常。而同一模块中的其他ABC:
from numbers import Real
from numbers import Complex
Real() # or Complex()
抛出:
TypeError: Can't instantiate abstract
上面是带有属性的uiautomator对象查看器屏幕截图。我使用的是通过pip install uiautomator安装的。我试图通过UI自动对象访问三个虚线设置按钮。我试过使用上列出的文档
下面是代码和错误:
import uiautomator as uia
d = uia.device() #below all are my attempts
>>> d(resourceId="com.android.camera2:id/three_dots").clickable
Traceback (most recent call last
我希望使一个类或函数不可调用,所以当callable函数在函数对象/类对象(如callable(function) )上使用时,它将返回False。我已经了解了如何阻止类被调用,并通过以下方法获得实例:
class Object:
def __new__(cls):
raise TypeError('{} is not callable'.format(cls.__name__))
但是当我使用callable(Object)时,它仍然返回True。如何使其不可调用,然后在使用False函数时返回callable?即使我用
Object.__new__
我有一个简单的代码,我得到了一个奇怪的错误:
from abc import ABCMeta, abstractmethod
class CVIterator(ABCMeta):
def __init__(self):
self.n = None # the value of n is obtained in the fit method
return
class KFold_new_version(CVIterator): # new version of KFold
def __init__(self, k):
a
我正在尝试做最基本的事情,那就是尝试通过输入函数从键盘上读取。 我试着在提供的其他链接中寻找其他解决方案。但这对我没什么帮助。因为它们是先前声明输入的那些。它抛给我错误:- File "<ipython-input-169-5d707bffda8e>", line 1, in <module>
a = input("Enter the number")
TypeError: '_io.TextIOWrapper' object is not callable 我试着用'input‘从键盘上获取输入
为什么不能在下面的代码中从模块Callable中获得collections的定义?
如何在模块中获得类的定义?谢谢。
>>> from collections import Callable
>>> inspect.getsource(Callable)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/inspect.py", line 944, in
当我的(python2.7)程序退出时,我得到了许多被忽略的异常。但是由于项目规模很大,而且是基于别人开发的项目,所以很难用这样的信息来定位bug。有没有办法获得异常跟踪,或任何其他方法,可以帮助?谢谢。
Exception TypeError: "'NoneType' object is not callable" in <object repr() failed> ignored
Exception TypeError: "'NoneType' object is not callable" in <obje
语境
我有一个相对复杂的类层次结构的python应用程序。它需要与python2.6一起工作,直到python3.5(我知道,范围很大!),而且我一直对ABC有特殊的问题。我正在使用six库的with_metaclass来减轻一些伤害,但这仍然是个问题。
一组特殊的课程一直给我带来麻烦。以下是简化后的格式:
from abc import ABCMeta
from six import with_metaclass
# SomeParentABC is another ABC, in case it is relevant
class MyABC(with_metaclass(ABCMeta
我有一个基类,其他类应该从中继承:
class AppToolbar(wx.ToolBar):
''' Base class for the Canary toolbars '''
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# ... a few common implementation details that work as expected...
self._Popula
我将经常使用的模块放在子目录lib/中,并期望通过以下方式将所有模块加载到main.py中(参见)
from lib import *
但是遇到问题的TypeError: 'module' object is not callable。更具体地说,在main.py中
#!/usr/bin/env python
from lib import * # cause: TypeError: 'module' object is not callable
#from lib.DominatingSets import * # it works
dominatin
既然range对象是可订阅的,为什么itertools.repeat对象不能订阅?
In [10]: range(3, 10)[3]
Out[10]: 6
In [11]: import itertools as it
In [12]: it.repeat(5)[3]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython
我试图理解Python中的“可调用性”是什么,类是可调用的意味着什么。我在玩以下代码:
class A(object):
def __init__(self):
pass
print("Is A callable? " + str(callable(A)))
a=A()
print("created a")
a()
这将产生以下结果:
Is A callable? True
created a
Traceback (most recent call last):
File "test2.py", line 11
我理解functools.wraps的目的--继承__doc__、__name__等属性,但我很难解释为什么会发生以下情况。我在Python中有这个装饰函数:
from functools import update_wrapper
class Environment:
...
def requires_environment(function: Callable) -> Callable:
def wrapped_function(*args, environment, **kwargs):
if not isinstance(environment,
在我的代码中,我有下面这行代码。 from inspect import isclass
if isclass(route.handler) and issubclass(route.handler, web.View): 不幸的是,这行代码在我的生产环境中给出了下面的异常。 TypeError: issubclass() arg 1 must be a class 据我所知,Python (3.7.7)编译器将首先检查if语句的第一个条件,如果结果为false,则不会检查第二个条件。因此,我必须得出结论,route.handler一定是一个类,因此我得到的TypeError不应该发生。我