Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Treat error ?
#7
(Apr-16-2020, 11:40 AM)buran Wrote:
o_method = getattr (o_class, v_metget)
AttributeError: type object 'Runcode' has no attribute 'other'
In your code you don't try to check for "other". Please, post full traceback and the actual code that produce the error.

(Apr-16-2020, 10:28 AM)JohnnyCoffee Wrote: So far so good the code above runs perfectly.

There are couple of issues with your code, line 13. It's not possible your code is actually running:
class = getattr (module, conget)
1. class is reserved word, so it's not possible to assign to it (use it as variable name). This will raise SynatxError.
>>> class = 'foo'
  File "<stdin>", line 1
    class = 'foo'
          ^
SyntaxError: invalid syntax
>>>
2 module is not defined and will result in NameError.


Here is working example
>>> from importlib import import_module
>>> my_module = import_module('csv')
>>> my_attr = 'DictReader'
>>> test = hasattr(my_module, my_attr)
>>> test
True
>>> my_attr = 'NoExist'
>>> test = hasattr(my_module, my_attr)
>>> test
False
>>>

I had just written it wrong, on line 13 but the problem persists. The analysis you mentioned refers to checking the module and class. In my case it is to check if the class method exists and then I face the error ?
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