The problem here isn't that your function is "user-defined", the problem is that "x=B()" does not invoke a method called "B" inside your class, it invokes a method called "B" in the global namespace.
To illustrate what's happening, look at this code:
B="1"
class A():
B="2"
def myfunc(cls):
print B
a = A()
a.myfunc()
If you run that you'll see that the output is 1
.
If you change the print
statement to print A.B
you'll get 2
.
In your case you need to call A.B()
rather than simply B()
However, as others have pointed out, B()
is an instance method. It expects the first parameter it's passed to be an instance of the class. Depending on what B does, it's likely that you're going to have problems caused by the fact that you don't have an instance to pass it. You can work around this in various ways by passing it some other object (such as the class itself), or by creating a new object to pass in; but to me it seems that if C() needs to call an instance method, C() should be an instance method itself.
Difference between Class and Instance methods talks about the difference between class and instance methods.