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

  • Home
  • SEARCH
  • 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 7946667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:13:06+00:00 2026-06-04T01:13:06+00:00

>>> import __builtin__ >>> class MyClass: … def __init__(self): … self.a = 2 …

  • 0
>>> import __builtin__
>>> class MyClass:
...     def __init__(self):
...             self.a = 2
...             __builtin__.a = self.a
...
>>> myclass = MyClass()
>>> myclass.a = 4
>>> a = 2
>>> print a
2
>>> print myclass.a
4

I would expect a and myclass.a to have the same value. Why don’t they?

PS. Why you would use __builtin__ like this is another question.

  • 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-04T01:13:07+00:00Added an answer on June 4, 2026 at 1:13 am

    Python does not have references. Assigning a value e.g. using = rebinds the name.

    If you want such behaviour you need a mutable object, e.g. a list with one element:

    >>> import __builtin__
    >>> class MyClass:
    ...     def __init__(self):
    ...         self.a = [2]
    ...         __builtin__.a = self.a
    ...
    >>> myclass = MyClass()
    >>> myclass.a[0] = 4
    >>> a[0] = 2
    >>> print a
    [2]
    >>> print myclass.a
    [2]
    >>>
    

    However, reconsider if you really want to put stuff like this into __builtins__.

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

Sidebar

Related Questions

I have defined c:/temp/t.py as follows: class MyClass(object): def __init__(self): self._my_secret_thing = 1 def
import wx class MainFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self, parent, title=title, size=(640,480)) self.mainPanel=DoubleBufferTest(self,-1) self.Show(True) class DoubleBufferTest(wx.Panel):
my code(i was unable to use 'pickle'): class A(object): def __getstate__(self): print 'www' return
Say I derive from threading.Thread: from threading import Thread class Worker(Thread): def start(self): self.running
import java.lang.Math; public class NewtonIteration { public static void main(String[] args) { System.out.print(rootNofX(2,9)); }
import math def p(n): return 393000*((288200/393000)^n * math.exp(-(288200/393000)))/math.factorial(n) print p(3) When I run it,
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateDemo { public static void main(String[]
import threading event = threading.Event() event.set() print event.wait(1) None event.clear() print event.wait(1) None So
import java.io.*; import java.util.Scanner; import java.util.StringTokenizer; public class Filereader { public static void main(String[]
import java.lang.reflect.Array; public class PrimitiveArrayGeneric { static <T> T[] genericArrayNewInstance(Class<T> componentType) { return (T[])

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.