Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Treat error ?
#5
(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 True
Method 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?
Reply


Messages In This Thread
Treat error ? - by JohnnyCoffee - Apr-14-2020, 07:16 PM
RE: Treat error ? - by buran - Apr-14-2020, 07:49 PM
RE: Treat error ? - by JohnnyCoffee - Apr-14-2020, 11:39 PM
RE: Treat error ? - by buran - Apr-15-2020, 05:02 PM
RE: Treat error ? - by JohnnyCoffee - Apr-16-2020, 10:28 AM
RE: Treat error ? - by buran - Apr-16-2020, 11:40 AM
RE: Treat error ? - by JohnnyCoffee - Apr-16-2020, 11:23 PM
RE: Treat error ? - by buran - Apr-17-2020, 03:01 AM
RE: Treat error ? - by JohnnyCoffee - Apr-17-2020, 05:54 AM
RE: Treat error ? - by buran - Apr-17-2020, 07:30 AM
RE: Treat error ? - by JohnnyCoffee - Apr-17-2020, 07:35 AM
RE: Treat error ? - by buran - Apr-17-2020, 07:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to treat two token as one token(lexer)? hsunteik 1 3,613 Dec-28-2016, 12:26 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020