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 6247843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:56:58+00:00 2026-05-24T12:56:58+00:00

I bumped into this behaviour when trying to get class-decorators and method-decorators to play

  • 0

I bumped into this behaviour when trying to get class-decorators and method-decorators to play nicely together. Essentially, the method decorators would flag some of the methods as special with some dummy value, and the class decorator would come by after and fill in the value later. This is a simplified example

>>> class cow:
>>>     def moo(self):
>>>         print 'mooo'
>>>     moo.thing = 10
>>>
>>> cow.moo.thing
10
>>> cow().moo.thing
10
>>> cow.moo.thing = 5
AttributeError: 'instancemethod' object has no attribute 'thing'
>>> cow().moo.thing = 5
AttributeError: 'instancemethod' object has no attribute 'thing'
>>> cow.moo.__func__.thing = 5
>>> cow.moo.thing 
5

Does anyone know why cow.moo.thing = 5 does not work, even though cow.moo.thing quite clearly gives me 10? And why cow.moo.__func__.thing = 5 works? I have no idea why it does, but in randomly fiddling with stuff in the dir(cow.moo) list trying to get something to work it suddenly did, and i have no idea why.

  • 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-05-24T12:56:59+00:00Added an answer on May 24, 2026 at 12:56 pm

    For attribute lookup, Python is automatically using the real function attached to the instance method for you.

    For attribute setting, it is not.

    They are two separate operations depending on which side of the statement you’re on, even though they both use the . operator.

    When you access an instance method’s __func__, you’re manually accessing the real function that actually has the moo attribute.

    In Python 3 this will work as you would like / expect as methods are basically just functions.

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

Sidebar

Related Questions

I am trying to middle align an element, But I have bumped into this
I'm trying to implement AES in c# and I bumped into an error. This
I bumped into an additional question that I needed in regards to this: Using
I accidentally bumped into an ad like this: http://monotouch.net/DownloadTrial?ref=so1 . Then I start to
I'm not 100% convinced that this is a good idea, but I bumped into
I have bumped into this concept using Python distutils2/packaging . I did google it,
Recently I bumped into a problem where my OpenGL program would not render textures
I've been having trouble trying to get PIL to nicely downsample images. The goal,
Bumped into another templates problem: The problem: I want to partially specialize a container-class
Bumped into a strange situation here. Trying to extract cars from a sql database

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.