Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 输入类名并从列表中删除该类的对象_Python 3.x_List_Class - Fatal编程技术网

Python 3.x 输入类名并从列表中删除该类的对象

Python 3.x 输入类名并从列表中删除该类的对象,python-3.x,list,class,Python 3.x,List,Class,我想使用变量“classname”从列表中删除一个对象 list = [A, A, B] #objects inside a list classname = input() . #x = A list.remove(classname) #the problem is that classname is a string #an

我想使用变量“classname”从列表中删除一个对象

list = [A, A, B]                    #objects inside a list  
classname = input() .               #x = A
list.remove(classname)              #the problem is that classname is a string
                                    #and the list has no strings

有些对象知道它们的名称。如果
A
B
是类、函数、方法、描述符或生成器实例,则可以使用来确定它们的名称

class A:
    pass

class B:
    pass

l = [A, B, A, B]
remove = "A"
print([x for x in l if x.__name__ != remove])
# [<class '__main__.B'>, <class '__main__.B'>]
A类:
通过
B类:
通过
l=[A,B,A,B]
remove=“A”
打印([x代表l中的x,如果x.\uuuuu name\uuuuuu!=删除])
# [, ]

A和B是什么?你不能@它们是物体