Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:24:56+00:00 2026-06-11T11:24:56+00:00

I have a simple exception-logging decorator, which is handy for sending myself emails when

  • 0

I have a simple exception-logging decorator, which is handy for sending myself emails when my scripts throw exceptions.

def logExceptions(func):
   def wrapper():
      try:
         func()
      except Exception, e:
         logger.exception(e)

   return wrapper

However, if I want to decorate a class method, I have to modify wrapper() to take a ‘self’, otherwise I get the following error:

TypeError: wrapper() takes no arguments (1 given)

Of course, at that point I can’t use it to decorate any non-class methods, because then this error occurs:

TypeError: wrapper() takes exactly 1 argument (0 given)

Is there a clean way to tackle this problem? Thank you =)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:24:58+00:00Added an answer on June 11, 2026 at 11:24 am

    The usual thing is to define your wrapper so it accepts *args and **kwargs and passes them on to the function it wraps. This way it can wrap any function.

    Also, I get the impression that what you are calling a “class method” is what Python calls an “instance method”, and what you call “non-class method” is what Python calls a “function”. A “non-class method” (e.g., instance method) in Python takes a self argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the next simple logging code: function log($exception) { error_log($exception->getMessage() . \n, 3,
I have simple class with width and height member fields which define number of
I have a very simple application that illustrates the function of logging. I use
We're trying to create a simple to use webservice for logging exceptions and messages.
I have a simple WCF service which accept some data (wsHttpBiding) and returns a
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple php validation form that is halfway working. If you leave the
I have simple JavaScript snippet: var obrazek = [{nazwa: "Sniadanie", wiek: 100, autor: "Alicja"},{nazwa:
I have simple script with EventMachine, Fibers and faye require faye require em-synchrony require
I have simple database - one table with 6 collumns. 3 of them i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.