Maybe I'm not understanding the need for this... or how you are intending to
use it, but if it's going to be hardcoded is it possible to just pass
itself?? Maybe I'm oversimplifying this so don't laugh at me! haha

class foo():
    def __init__(self, instancedVarName):
        self.var = instancedVarName
        print "I'm assigned to %s" % self.var

>>> f = foo('f')
>>> I'm assigned to f

Dumb answer?

On Fri, May 1, 2009 at 9:20 AM, Eric Pavey <[email protected]> wrote:

>
> I've passed this around some other groups, and I'm being told
> "probably not possible".  But I thought I'd try here as well :)  This
> isn't realized specifically to Maya-Python, but since I'm trying to
> implement this in a module I'll use in Maya, I think it's applicable
> for this list too :)
>
> Given an object:
>
> class Foo(object):
>    def __init__(self):
>        # stuff....
>
> I'd like it to print, when instanced, something like this:
>
> >>> f = Foo()
> I’m assigned to f!
>
> But it seems prohibitively hard (based on my web and forum searches)
> for an object to know what variable name is has been assigned to when
> created.  Querying 'self' in __init__ returns a memory location, not
> the variable name passed in.
>
> If you're wondering why I'm trying to figure this out, this is just
> part of my continued learning of the language and pushing the bounds,
> to see what is possible ;)
>
> Any thoughts?
> >
>

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to