A Friday 04 September 2009 21:06:09 nicky van foreest escrigué:
> Hi,
>
> I realize my question is somewhat off-topic for the pytables
> community, but the problem originates from my using pytables.  In the
> skeleton code below I do not like to use the function's name to get
> the doc string.
>
> def dumFunction():
>     """This function will gain me with the Nobel Prize...in another
> life.""" fp = openFile("res.h5", mode='a')
>     results = []
>     resArray = fp.createArray(fp.root, "Pete", results,
> dumFunction.__doc__)
>
>
> Now I would rather not pass dumFunction.__doc__ as an argument.
> Instead, I want to use something like the C++ pointer this, that is,
> something like this.__doc__. In other words, how do I get a reference
> to the doc string, without having to use the function's name?

The next should do the trick:

    mydoc = getattr(eval(sys._getframe().f_code.co_name), "__doc__")


See recipe 14.7 of the excellent "Python Cookbook" book by Alex Martelli & 
David Ascher for details on this solution.

HTH,

-- 
Francesc Alted

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to