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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:46:03+00:00 2026-06-06T03:46:03+00:00

Normal way: class A: def __init__(self): self.a.b.c = 10 def another_method(self): self.a.b.c = self.a.b.c

  • 0

Normal way:

class A:
    def __init__(self):
        self.a.b.c = 10

    def another_method(self):
        self.a.b.c = self.a.b.c * 10

Aliased approach:

class A:
    def __init__(self):
        self.a.b.c = 10         
        alias self.aliased = self.a.b.c  # Creates an alias 

    def another_method(self):
        self.aliased = self.aliased * 10  # Updates value of self.a.b.c

How does one accomplish aliasing in Python? The reason I want to do this is to reduce cluttering due to long variable names. It’s a multi threaded environment, so simply copying to a local variable will not work.

  • 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-06T03:46:05+00:00Added an answer on June 6, 2026 at 3:46 am

    The solution to this is to use getter and setter methods – fortunately Python has the property() builtin to hide the ugliness of this:

    class A:
        def __init__(self):
            self.a.b.c = 10
    
        @property
        def aliased(self):
            return self.a.b.c
    
        @aliased.setter
        def aliased(self, value):
            self.a.b.c = value
    
        def another_method(self):
            self.aliased *= 10  # Updates value of self.a.b.c
    

    Generally, deeply nested attributes like self.a.b.c are a sign of bad design – you generally don’t want classes to have to know about objects that are 3 relationships away – it means that changes to a given item can cause problems throughout your code base. It’s a better idea to try and make each class deal with the classes around it, and no further.

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

Sidebar

Related Questions

Consider the following (broken) code: import functools class Foo(object): def __init__(self): def f(a,self,b): print
Is there a way to tune the Oracle client (InstantClient or the normal one)?
Is there any way to create something similar to this: class F[A] {def apply(a:
class BaseForm(forms.Form): def as_custom_table(self): Returns this form rendered as HTML <tr>s -- excluding the
Normal overriding would work this way: class Fruit { public: string color(); }; string
Consider the following example: class A: @property def x(self): return 5 So, of course
My code contains: Class GroupForm(forms.ModelForm): .... def clean_name(self): .... raise forms.ValidationError(mark_safe('....<a href={% url edit
Here is the normal way I would do things in C++: class object {
I use numpy.random.normal function in a tough loop in a class. class MyClass(MyBaseClass): def
Is the normal way to do this to just make 2 cols in my

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.