Any method to denote object assignment?

Posted by Droogans on Stack Overflow See other posts from Stack Overflow or by Droogans
Published on 2012-09-05T03:35:41Z Indexed on 2012/09/05 3:37 UTC
Read the original article Hit count: 101

Filed under:
|
|

I've been studying magic methods in Python, and have been wondering if there's a way to outline the specific action of:

a = MyClass(*params).method()

versus:

MyClass(*params).method()

In the sense that, perhaps, I may want to return a list that has been split on the '\n' character, versus dumping the raw list into the variable a that keeps the '\n' intact.

Is there a way to ask Python if its next action is about to return a value to a variable, and change action, if that's the case? I was thinking:

class MyClass(object):
    def __init__(*params):
        self.end = self.method(*params)

    def __asgn__(self):
        return self.method(*params).split('\n')

    def __str__(self):
        """this is the fallback if __asgn__ is not called"""
        return self.method(*params)

© Stack Overflow or respective owner

Related posts about python

Related posts about oop