1

I've been trying out this code and am oblivious to why it does not work.

class Foo(object):
    def __init__(self):
        self=False
        print self #Prints false
print Foo() #Prints `<__main__.Foo object at 0x026B3970>`

I thought it might be that self is only a reference to the object but passing self=[] or self=object does not work either.

I know this approach is not exactly a good technique but I am wondering why it does not set the object to the specific value.

0

1 Answer 1

2

It doesn't ignore the assignment. The assignment works just fine, you created a local name that points to False.

If you really want to do what you are doing...

class Test(object):
    def __new__(*args):
        return False
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.