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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:16:46+00:00 2026-06-02T07:16:46+00:00

Or does the attribute have to be defined outside of any class methods? So

  • 0

Or does the attribute have to be defined outside of any class methods?

So my descriptor object is this. The IDN object already has some information about the UserNameField, so I want to use it.

class UserNameElement(basePageElement):
    _testMethodName="UserNameElement Test method"
    def __init__(self, IDN, PTF):
        print "creating UserNameElement"
        self.locator =  IDN.UserNameField()

And here is my calling class. Where I want to instantiate the UserNameElement object

class LoginPageObject(basePageObject):
    _testMethodName="LoginPageObject Test method"
    print "creating LoginPageObject"
    def __init__(self, BaseURL):
        super(LoginPageObject, self).__init__()
        self.username=UserNameElement(IDN=self.IDN, PTF=self.PTF)

It seems that the standard process would put the username= in in the general class definition, like this:

class LoginPageObject(basePageObject):
    _testMethodName="LoginPageObject Test   method"
    username=UserNameElement()
    print "creating LoginPageObject"
    def __init__(self, BaseURL):
        super(LoginPageObject, self).__init__()

But then I don’t have the PTF and IDN that I define in the basePageObject class.

What can I do to make those available when the username attribute is created?

Thanks

  • 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-02T07:16:47+00:00Added an answer on June 2, 2026 at 7:16 am

    I am afraid that will not be possible, as your attribute username will be resolved via normal attribute access see http://docs.python.org/howto/descriptor.html#invoking-descriptors

    May be you can get away by overriding __getattribute__ and simulating what type.__getattribute__() does

    class MyD(object):
        def __init__(self, val):
            self.val = val
    
        def __get__(self, obj, objtype):
            return self.val
    
        def __set__(self, obj, val):
            self.val = val
    
    class C(object):
        a = MyD(42)
        def __init__(self):
            self.d = MyD(42)
    
        def __getattribute__(self, name):
            attr = super(C, self).__getattribute__(name)
            if hasattr(attr, '__get__'):
                return attr.__get__(self, C)
            return attr
    
    c = C()
    print c.d
    print c.a
    

    Output:

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

Sidebar

Related Questions

I have defined an assembly level attribute class FooAttribute like this: namespace Bar {
I have a Moose class with an attribute that does a certain role: has
what does this code performs? if(object.jquery){ .... } I don't know what jQuery attribute
I have custom attribute defined like so: [AttributeUsage(AttributeTargets.Field)] public class EnumDisplayAttribute : Attribute {
I have following problem. In my view model I defined some list properties as
Originally, the model attribute location for Item class was defined like the following: location
Does it have an adverse effect on a browser's performance to assign class name
Background: I have a class modeling a chip with registers, the chip has a
I have a DefaultStyle and then another Style defined like this <Style TargetType={x:Type my:CustomButton}
Say I want to make a decorator for methods defined in a class. 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.