1

I'm working on my own version of the module logging, I'm almost finished with the base, but I get an error that I cant solve on my own.
I tried looking at others questions on so, but nothing helped me.
(Other questions I looked at: Question 1 - Question 2 - Docs)
The full error:

Traceback (most recent call last):
  File ".\server.py", line 20, in <module>
    debugger.status(True)
TypeError: status() missing 1 required positional argument: 'inp'

and my code:

class debugger():
    def __init__(self, state=False):
        self.state = state

    def status(self, inp:bool):
        if inp == True and self.state == False: print('Debugger activated')
        elif inp == True and self.state == True: print('Debugger alredy started')
        elif inp == False and self.state == True: print('Debugger stopped')
        else: print('Debugger alredy stopped')
        self.state = inp

    def log(self, msg:str):
        if self.state == True: print(f'[DEBUGGER]: {msg}')
        else: pass

    def __repr__(self):
        if self.state == True: return 'Debugger status: Active'
        else: return 'Debugger status: Disabled'

debugger.status(True)
debugger()
debugger.log('Test from debugger')

EDIT:
If i try to change the 3 lines at the bottom to:

debugger.status(debugger, True)
debugger()
debugger.log(debugger, 'Test from debugger')

I get:

Traceback (most recent call last):
  File ".\server.py", line 22, in <module>
    debugger.status(debugger, True)
  File ".\server.py", line 8, in status
    if inp == True and self.state == False: print('Debugger activated')
AttributeError: type object 'debugger' has no attribute 'state'

1 Answer 1

3

You need to call both methods on an instance of the class, not the class itself.

d = debugger()
d.status(True)
d.log('Test from debugger')
Sign up to request clarification or add additional context in comments.

1 Comment

well, I'm starting to think that I need to sleep more... Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.