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__':
>   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 of printing it from within the
> main without creating an object of the MyClass type. I need to assign
> the name of the class within my script, to a variable in main.
> 
> Thanks,
> 
> Barry.
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


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 of printing it from within the
> main without creating an object of the MyClass type. I need to assign
> the name of the class within my script, to a variable in main.

Yes::

print MyClass.__name__

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


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
> above in the init, but is there any way of printing it from within the
> main without creating an object of the MyClass type. I need to assign
> the name of the class within my script, to a variable in main.
> 
> Thanks,
> 
> Barry.
> 

 >>> class A:
... pass
...
 >>> print A.__name__
A
 >>>
-- 
Robin Becker

-- 
http://mail.python.org/mailman/listinfo/python-list


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 way of printing it from within the
main without creating an object of the MyClass type. I need to assign
the name of the class within my script, to a variable in main.

Thanks,

Barry.

-- 
http://mail.python.org/mailman/listinfo/python-list