Apr-16-2020, 10:28 AM
(Apr-15-2020, 05:02 PM)buran Wrote: I have no idea what are you doing to get the error. The code you show does nothing because lines 4-6 are inside class you never use. Fix indentation and it works.
Here is the code in repl.it
Will I try to give a better understanding?
I have the following code below that aims to access module's dynamically:
# Native module import: import_module from importlib import import_module appget = "website" conget = "Runcode" metget = "screen" # Import dynamic module: activating the controller and the standard method: pathmod = "apps". + appget + ".controllers." + conget # Import dynamic module: passing as parameter or path assigned in the variable: modulo = import_module (pathmod) # Retrieve a class: last as attractive parameters in the class-controller variable: class = getattr (module, conget) # Retrieve the method: passed, as a parameter assigned to the method-controller variable: method = getattr (class, metget) # Instance or object: related to the class method: output = method () # Return : print (output)So far so good the code above runs perfectly.
The problem is that I need to get the boolean result of the class method, I tried to do this using the python hasattr method, managing to get the Boolean value True, but if the class method does not exist (any other) I get the following error message:
Existing Method: True
# Access the controller class and check the existence of the method: metexist = hasattr (class, metget) # Return : print (metexist) # I get TrueMethod does not exist: Error message in the terminal
o_method = getattr (o_class, v_metget) AttributeError: type object 'Runcode' has no attribute 'other'How can I get the boolean value as False, as opposed to the error message?