Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

How can I find the superclass of a Function Object in Python?

So if I code:

a=False
print(type(a))
print(bool.mro())

The result is:

<class 'bool'>
[<class 'bool'>, <class 'int'>, <class 'object'>]

What works perfectly well in my point of view, although, if I run the following code I get an error:

def F():
  pass
print(type(F))
print(function.mro())

The error:

<class 'function'>
NameError: name 'function' is not defined

how is " function" not defined since it says that is a class?

question from:https://stackoverflow.com/questions/65876903/how-can-i-find-the-superclass-of-a-function-object-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your first lines of code work because bool is a builtin function This is not the case for function


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...