Re: Getting a class name

2007-02-19 Thread Fuzzyman
On Feb 19, 5:11 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 18 Feb 2007 20:56:48 -0300, Fuzzyman [EMAIL PROTECTED] escribió: [somebody] wrote: def getCodeName(deap=0): return sys._getframe(deap+1).f_code.co_name class MyClass (object): name = getCodeName()

Re: Getting a class name

2007-02-19 Thread Gabriel Genellina
En Mon, 19 Feb 2007 17:25:56 -0300, Fuzzyman [EMAIL PROTECTED] escribió: On Feb 19, 5:11 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 18 Feb 2007 20:56:48 -0300, Fuzzyman [EMAIL PROTECTED] escribió: [somebody] wrote: def getCodeName(deap=0): return

Re: Getting a class name

2007-02-18 Thread Gabriel Genellina
En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf [EMAIL PROTECTED] escribió: I suppose that you wont get class name into its code (or before definition end) but not into a method definition. import sys def getCodeName(deap=0): return sys._getframe(deap+1).f_code.co_name class MyClass

Re: Getting a class name

2007-02-18 Thread Fuzzyman
On Feb 17, 8:33 pm, deelan [EMAIL PROTECTED] wrote: Harlin Seritt wrote: Hi, How does one get the name of a class from within the class code? I tried something like this as a guess: self.__name__ Get the class first, then inspect its name: class Foo(object): pass ... f = Foo()

Re: Getting a class name

2007-02-18 Thread Daniel Klein
On 18 Feb 2007 04:24:47 -0800, Fuzzyman [EMAIL PROTECTED] wrote: On Feb 17, 8:33 pm, deelan [EMAIL PROTECTED] wrote: Harlin Seritt wrote: Hi, How does one get the name of a class from within the class code? I tried something like this as a guess: self.__name__ Get the class first,

Re: Getting a class name

2007-02-18 Thread Michele Simionato
On Feb 18, 1:24 pm, Fuzzyman [EMAIL PROTECTED] wrote: Why is the __name__ attribute not available to the instance? Why don't normal lookup rules apply (meaning that a magic attribute will be looked up on the class for instances) ? Because __name__ isn't really an attribute, it is a descriptor

Re: Getting a class name

2007-02-18 Thread Fuzzyman
On Feb 18, 1:22 pm, Michele Simionato [EMAIL PROTECTED] wrote: On Feb 18, 1:24 pm, Fuzzyman [EMAIL PROTECTED] wrote: Why is the __name__ attribute not available to the instance? Why don't normal lookup rules apply (meaning that a magic attribute will be looked up on the class for

Re: Getting a class name

2007-02-18 Thread goodwolf
On Feb 18, 9:17 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf [EMAIL PROTECTED] escribió: I suppose that you wont get class name into its code (or before definition end) but not into a method definition. import sys def getCodeName(deap=0):

Re: Getting a class name

2007-02-18 Thread Gabriel Genellina
En Sun, 18 Feb 2007 14:14:41 -0300, goodwolf [EMAIL PROTECTED] escribió: On Feb 18, 9:17 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf [EMAIL PROTECTED] escribió: I suppose that you wont get class name into its code (or before definition

Re: Getting a class name

2007-02-18 Thread Bruno Desthuilliers
Gabriel Genellina a écrit : En Sun, 18 Feb 2007 14:14:41 -0300, goodwolf [EMAIL PROTECTED] escribió: On Feb 18, 9:17 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf [EMAIL PROTECTED] escribió: I suppose that you wont get class name into its

Re: Getting a class name

2007-02-18 Thread Fuzzyman
On Feb 18, 11:54 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Gabriel Genellina a écrit : En Sun, 18 Feb 2007 14:14:41 -0300, goodwolf [EMAIL PROTECTED] escribió: On Feb 18, 9:17 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf [EMAIL

Re: Getting a class name

2007-02-18 Thread Gabriel Genellina
En Sun, 18 Feb 2007 20:56:48 -0300, Fuzzyman [EMAIL PROTECTED] escribió: [somebody] wrote: def getCodeName(deap=0): return sys._getframe(deap+1).f_code.co_name class MyClass (object): name = getCodeName() + '!' What's the advantage over MyClass.__name__? I were asking,

Getting a class name

2007-02-17 Thread Harlin Seritt
Hi, How does one get the name of a class from within the class code? I tried something like this as a guess: self.__name__ Obviously it didn't work. Anyone know how to do that? Thanks, Harlin -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a class name

2007-02-17 Thread deelan
Harlin Seritt wrote: Hi, How does one get the name of a class from within the class code? I tried something like this as a guess: self.__name__ Get the class first, then inspect its name: class Foo(object): pass ... f = Foo() f.__class__.__name__ 'Foo' HTH -- d. --

Re: Getting a class name

2007-02-17 Thread goodwolf
I suppose that you wont get class name into its code (or before definition end) but not into a method definition. import sys def getCodeName(deap=0): return sys._getframe(deap+1).f_code.co_name class MyClass (object): name = getCodeName() + '!' --

Re: Getting a class name from within main

2007-02-08 Thread Chris Lambacher
On Wed, Feb 07, 2007 at 01:02:39AM -0800, [EMAIL PROTECTED] wrote: Hi, Lets say I have the following class - class MyClass: def __init__(self): print (__name__.split(.))[-1] I would spell this: print self.__class__.__name__ if __name__ == '__main__':

Getting a class name from within main

2007-02-07 Thread bg_ie
Hi, Lets say I have the following class - class MyClass: def __init__(self): print (__name__.split(.))[-1] if __name__ == '__main__': MyClassName = MyClass I can print the name of the class from within the class scope as seen above in the init, but is there any

Re: Getting a class name from within main

2007-02-07 Thread Robin Becker
[EMAIL PROTECTED] wrote: Hi, Lets say I have the following class - class MyClass: def __init__(self): print (__name__.split(.))[-1] if __name__ == '__main__': MyClassName = MyClass I can print the name of the class from within the class scope as seen

Re: Getting a class name from within main

2007-02-07 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], bg_ie wrote: class MyClass: def __init__(self): print (__name__.split(.))[-1] if __name__ == '__main__': MyClassName = MyClass I can print the name of the class from within the class scope as seen above in the init, but is there any way

getting the class name of a subclass

2005-07-20 Thread flupke
I have the following test code setup, trying to get the class name of a subclass in the super class. (Reason why i want this is described below) file class_name_start.py import class_name as cn obj = cn.B() obj.printclass() file class_name.py

Re: getting the class name of a subclass

2005-07-20 Thread George Sakkis
flupke [EMAIL PROTECTED] wrote: I have the following test code setup, trying to get the class name of a subclass in the super class. (Reason why i want this is described below) file class_name_start.py import class_name as cn obj = cn.B() obj.printclass()

Re: getting the class name of a subclass

2005-07-20 Thread flupke
George Sakkis wrote: snip Make printclass a class method: class A(object): def __init__(self): print I'm A # for python 2.4 @classmethod def printclass(cls): print Module, cls.__module__ print Class, cls.__name__ # for 2.3 or older

Re: getting the class name of a subclass

2005-07-20 Thread Dan Sommers
On Wed, 20 Jul 2005 14:06:57 GMT, flupke [EMAIL PROTECTED] wrote: file class_name.py class A(object): def __init__(self): print I'm A def printclass(self): print Name ,__name__ print Class ,A.__name__ Why A.__name__ and not