* Kent Johnson <[EMAIL PROTECTED]> [051214 16:00]:
> Tim Johnson wrote:
> > I was pleasantly surprised to notice in a previous thread that python
> > can automagically retrieve a class name thru __class__.__name__
> > 1)Can someone point me to further documentation on this topic?
> 
> __name__ and __module__ at least are documented here:
> http://docs.python.org/ref/types.html#l2h-118
> 
> You can also try dir(type) to see attributes of type 'type', the base class 
> of all 
> new-style classes, or dir(A) for any class A to see attributes of the class. 
> Many of the 
> special attributes (__xxx__) are referenced in the index to the Python 
> Reference Manual.
> http://docs.python.org/ref/genindex.html
> 
> > 2)Is it possible for the name of a class method to be 
> >   programmatically retrieved from within the scope of the method?
> >   If so, how? and pointers to docs would be welcome also.
> 
> You can look at the stack frame to find out what method you are in. See for 
> example
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062
 
  Thanks! This is really nice! I'm too old to write things like
  wwwoooo! - so I won't - but I am impressed.
  quick, handy function here:
def Here():
    """ Return file, name and line number of calling function"""
    return 'File: %s Function: %s Line Number: %s' % \
           (sys._getframe(1).f_code.co_filename,
            sys._getframe(1).f_code.co_name,
            sys._getframe(1).f_lineno)

Must tie a string around my finger with "sys._getframe" on it.
I'm sure it has many other goodies.
cheers
======
Tim Johnson <[EMAIL PROTECTED]>
      http://www.alaska-internet-solutions.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to