[SciPy-User] (pas de sujet)

Chris Weisiger cweisiger at msg.ucsf.edu
Fri Apr 1 15:22:48 EDT 2011


Keep in mind that if you ever anticipate showing your code to someone else,
it pays off big-time to be verbose. Terse code is harder to search, harder
to understand at a glance, harder to trace, and generally harder to
understand. Also keep in mind that the you one month down the line counts as
"someone else". :) On the assumption that any code you write will be used
for more than a month, then, you should err on the side of verbosity.

Invariably I find that the cost to me of typing out something like
"scipy.ndimage.map_coordinates" instead of just e.g. "nd.map_coordinates"
more than pays off by the time saved down the road when I have to come back
and modify the code. Likewise the cost of naming a variable "costOfPath" (or
even just "cost") instead of "c". Typing is not the roadblock to efficient
coding; thinking is. The less time you have to waste figuring out what code
you've already written does, the better.

-Chris

On Fri, Apr 1, 2011 at 12:13 PM, Agile Aspect <Agile.Aspect at gmail.com>wrote:

> Renato Fabbri wrote:
> > for a long time i imported all libraries with a capital letter, so a
> > typical first line would be:
> >
> > import numpy as N, pylab as P, scikits.audiolab as A, pywt as W, scipy as
> S
> >
> > now i find that ugly and unconfortable (as subjective as that may
> > sound..) and i do:
> >
> > import numpy as n, pylab as p, scikits.audiolab as a, pywt as w, scipy as
> s
> >
> > which leads me to nice looking code and confortable writing:
> >
> > avar=n.arange(100)
> > p.plot(avar,avar**2)
> > p.show()
> >
> > i get 10x more girls now.
>
> Works for me too!
> >
> >
> > 2011/4/1 Sebastian Haase <seb.haase at gmail.com>:
> >> On Fri, Apr 1, 2011 at 7:06 PM, Christopher Barker
> >> <Chris.Barker at noaa.gov> wrote:
> >>> On 4/1/11 5:00 AM, midel wrote:
> >>>> I began using scipy a few days ago and I think a long story between us
> is beginning ;) I come from the Matlab/Scilab world and I have no big
> problem using SciPy.
> >>>>
> >>>> Well, in fact, I have one problem, that is why I come here ! I will
> try to explain.
> >>>>
> >>>> I have a main program in one file "verif.py" and I want it to import
> functions that i have defined in another file "fonctions.py". I import Scipy
> in the main program but I also need the scipy functions to be available in
> the functions and do not manage to do so.
> >>>>
> >>>> The main verif.py program is :
> >>>>
> >>>>        from scipy import *
> >>>>        from fonction import truc
> >>> I think your immediate question was answered, but a suggestion:
> >>>
> >>>  From "The Zen of Python":
> >>>
> >>> "Namespaces are one honking great idea -- let's do more of those!"
> >>>
> >>> Matlab puts eveyting in one namespace -- this is convenient for
> >>> interactive use at the command line, but gets really painful after a
> >>> while for larger project. I HIGHLY recommend that you get out of that
> >>> habit, and use python namespaces. What that means is that you don't use
> >>> "import *" EVER.
> >>>
> >>> Some module names are a bit long to type if you are calling a lot of
> >>> functions, so you can give them shorter names when you import. For
> >>> instance, most folks now use:
> >>>
> >>> import numpy as np
> >>>
> >>> and often
> >>>
> >>> import scipy as sp
> >>>
> >>>
> >>> So your code would look like:
> >>>
> >>> The main verif.py program is :
> >>>
> >>>       import fonction
> >>>
> >>>       a=2;
> >>>       b=fonction.truc(a);
> >>>       print b
> >>>
> >>>
> >>>
> >>> fonction.py is :
> >>>
> >>>       import numpy as np
> >>>
> >>>       def truc(machin):
> >>>             plouc=machin*2;
> >>>             A=np.array([[1,2],[3,4]]);
> >>>             return A
> >>>
> >>>
> >>> Note that "from fonction import truc" is often fine, too -- you are
> >>> being explicit about exactly where "truc" came from.
> >>>
> >>> Another one from "the Zen of Python"
> >>>
> >>> "Explicit is better than implicit"
> >>>
> >>> This may seem difficult and like too much typing at first, but believe
> >>> me, it really is a better way to write code.
> >>>
> >>> -Chris
> >> try
> >>
> >>>>> import this
> >> ;-)
> >>
> >> - Sebastian Haase
> >> _______________________________________________
> >> SciPy-User mailing list
> >> SciPy-User at scipy.org
> >> http://mail.scipy.org/mailman/listinfo/scipy-user
> >>
> >
> >
> >
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110401/2c6eb1a2/attachment.html>


More information about the SciPy-User mailing list