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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:50:25+00:00 2026-06-16T23:50:25+00:00

In some cases, I want to use instance method in class creation time. I

  • 0

In some cases, I want to use instance method in class creation time.

I just want to use self in permissions list..This is my question

But it does not work. Is it some ways to solve the problem?

class PermissionChecker(object):
    # how to use self in class create time.
    permissions = [self.is_superuser(), self.is_god()]

    def is_superuser(self):
        # use self.property just like self.name...
        return True

    def is_god(self):
        return True

class Child(PermissionChecker):
    permissions = PermissionChecker.permissions + [self.is_coder(),]

    def is_coder(self):
        return True
  • 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-16T23:50:27+00:00Added an answer on June 16, 2026 at 11:50 pm

    It looks like you are confusing the term attribute with property; you cannot use self in the class definition itself, it is only available to a method.

    I think you are looking for the property descriptor:

    class PermissionChecker(object):
        @property
        def permissions(self):
            return [self.is_superuser(), self.is_god()]
    
        def is_superuser(self):
            # use self.property just like self.name...
            return True
    
        def is_god(self):
            return True
    

    By using property (above used as a @ decorator) you turn a method into an attribute:

    >>> pcheck = PermissionChecker()
    >>> pcheck.permissions
    [True, True]
    

    The permissions method is called every time the .permissions attribute is accessed on an instance.

    Alternatively, set the list in the __init__ initializer:

    class PermissionChecker(object):
        def __init__(self):
            self.permissions = [self.is_superuser(), self.is_god()]
    
        def is_superuser(self):
            # use self.property just like self.name...
            return True
    
        def is_god(self):
            return True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use case: I've just entered insert mode, and typed some text. Now I want
I want to use CASE in my stored procedure. I am getting some syntax
I have a 404.html page, but in some cases I want to be able
I have a set of radio buttons. In some cases I want the user
For example in some cases after POST or GET request I want to redirect
I only want to show my title attribute in some cases. I don't want
I am using Cocos2D for my main framework. In some cases, I want Cocos2D
I want to write some test cases for my web app, but stuck at
What I wanna do is a method that can generate instance of Class X
In some class method, A, I need to call a library method B, which

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.