<br><br><div class="gmail_quote">On Fri, Nov 18, 2011 at 10:40 AM, Chao YUE <span dir="ltr"><<a href="mailto:chaoyuejoy@gmail.com">chaoyuejoy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Thanks to all people for this very nice discussions.<br><br>the solutions are more that what I want!! and help me to clarify some concepts, and really begin to use class as a beginner :)<br></blockquote><div><br><br>FYI: Just a day or so ago, I stumbled across the same question in the Python FAQ:<br>

   <a href="http://docs.python.org/faq/programming.html#how-can-my-code-discover-the-name-of-an-object">http://docs.python.org/faq/programming.html#how-can-my-code-discover-the-name-of-an-object</a><br><br>Warren<br><br>
 <br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br>I would say either Olivier or denis's solution can solve my problem completely.<br>


<br>cheers, <br><br>Chao<br><br><div class="gmail_quote">2011/11/18 denis <span dir="ltr"><<a href="mailto:denis-bz-gg@t-online.de" target="_blank">denis-bz-gg@t-online.de</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


  as Olivier and Chris say, use a dict from the start.<br>
To make this a bit easier / more readable,<br>
use this tiny class Dotdict:<br>
<br>
class Dotdict( dict ):<br>
    """ d = dotdict(),  d.key same as d["key"] """<br>
        # aka Bag, Bunch<br>
        # cPickle.dumps( d, -1 ): PicklingError in 2.6.4<br>
    def __init__(self, **kwargs):<br>
            dict.__init__(self, kwargs)<br>
            self.__dict__ = self<br>
<br>
d = Dotdict()<br>
d.a = np.arange(10)<br>
d.b = np.ones((3,4))<br>
d.b[1,2] += 1<br>
print d.b<br>
<br>
<br>
One can also save all the d.* arrays like this:<br>
<br>
def savedotdict( d, prefix="d.", save=np.savetxt, **kwargs ):<br>
    """ save all d.* to files """<br>
    for name, val in d.items():<br>
        out = prefix + name<br>
        if isinstance( val, basestring ):<br>
            with open( out, "w" ) as f:<br>
                f.write( val.rstrip() )<br>
                f.write( "\n" )<br>
        else:<br>
            print "saving %s to %s" % (val.shape, out)<br>
            save( out, val, **kwargs )<br>
<br>
<a href="http://d.info" target="_blank">d.info</a> = "2011-11-18 nov kilroy"  # From()<br>
savedotdict( d, "d.", fmt="%.3g" )<br>
<br>
cheers<br>
  -- denis<br>
<br>
(If you use this, could you post it to the numpy-discussion group<br>
please ?<br>
It rejects me, grr.)<div class="im"><br>
<div><div></div><div><br>
<br>
On Nov 10, 11:17 am, Chao YUE <<a href="mailto:chaoyue...@gmail.com" target="_blank">chaoyue...@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> Does anyone know how I can quickly use the name of a ndarray as a string?<br>
</div></div></div></blockquote></div><br><br clear="all"><div><div></div><div class="h5"><br>-- <br><div>***********************************************************************************</div>
<div>Chao YUE<br>Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)<br>UMR 1572 CEA-CNRS-UVSQ<br>Batiment 712 - Pe 119<br>91191 GIF Sur YVETTE Cedex</div>
<div>Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16<br></div>

<div>************************************************************************************</div><br>
</div></div><br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br>