> Emailing this instead of "newpost" because of the attachment.
> This worksheet works well ONCE when it starts unevaluated. Reediting the
> data followed by "Action>Evaluate all" induces "TypeError: 'str' object
> is not callable". My way out is to "Delete output" save and quit and
> reopen. But I do not understand what happens.

Even without looking at the code, from the error message alone, I know
that there's a function name that you've rebound to a string, and when
you're running it the second time, it's got the string value instead
so the call fails.  So the only question is which function it is!

Looking at the code quickly reveals the problem: you've reassigned the
name "n", but you also use it as an abbreviation for numerical_approx,
so that the second time it has the value "Jeu 07h00", which is a
string, so n(mean((Sys[3*i],Sys[3*i+1],Sys[3*i+2])),digits=3) and
similar calls fail.

Workarounds (choose your favourite):

(1) add a reset() at the start of the worksheet, so everything returns
to normal, including "n".  This doesn't solve the problem that after
you use "n" as a variable you can't use it for numerical_approx,
though.

(2) Use numerical_approx instead of n.

(3) Avoid "n" as a variable.

(4) Choose something else -- nn, or nap, or whatever -- and use it
instead ("nn = numerical_approx", and then "nn(3.2445,digits=2)".

BTW, I see you're still writing

for i,j in enumerate(temps):
    for k,l in enumerate(mesuresF):
        for m,n in enumerate(heuresF):
            if m==k:
                if i==k:
                    print l[-1],"  ",l[0],"  ",l[1:4]

It's more Pythonic to write something like

for t,m,h in zip(temps, mesuresF, heuresF):
    print m[-1],"  ",m[0],"  ",m[1:4]

After all, if there are a thousand data points in
temps/mesuresF/heuresF, then the above loop will take forever to
finish (1000^3=10^9)!

"Flat is better than nested", we say, although in this particular loop
you only seem to be using one of the variables anyway, so "for m in
mesuresF:" looks like it should work.

For those of us who grew up with C or Fortran, it's hard to get out of
the habit of using loop indices everywhere, but it makes life much
better once you do. :^)

[For the record, I think encouraging people to use "n" as an alias for
numerical_approx was an unfortunate decision in the first place; it's
about a thousand times too common as a variable name to use as a
function name.]

Hope that helps!


Doug

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to