Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Treat error ?
#9
(Apr-17-2020, 03:01 AM)buran Wrote: I give up. My example is doing exactly what your "working", but actually not working example, for existing and non-existing attribute. You keep saying that the problem persist, but never show actual working code that reproduce the error and full traceback produced.

buran, i'm sorry if I didn't post the corrected code, I describe below:

# Native Module Import: import_module
from importlib import import_module

v_appget = "website"
v_conget = "runcode"
t_conget = "Runcode"
v_metget = "scree" # method does not exist

# Import dynamic module: calling the controller and pattern method:
v_pathmod = "apps." + v_appget + ".controllers." + v_conget
# Import dynamic module: passing as path the path assigned to the variable:
o_module = import_module (v_pathmod)
# Retrieve the class: passed as an attribute parameter in the class-controller variable:
o_class = getattr (o_module, t_conget)
# Retrieve the method: passed as an attribute parameter in the method-controller variable:
o_method = getattr (o_class, v_metget, None)
# Instantiate the object: related to the class method:
o_return = o_method ()
# Access the controller class and check the existence of the method:
o_metexist = hasattr (o_class, v_metget)
# Output:
print (o_metexist)
Thus it generates the error, because the method of the class does not exist according to the variable (v_metget), above. The idea would be to obtain the Boolean False result instead of the error below:

o_return = o_method()
TypeError: 'NoneType' object is not callable
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