[Tutor] attribute error
Alan Gauld
alan.gauld at btinternet.com
Sun Jul 29 09:23:55 CEST 2007
"Sara Johnson" <sarliz73 at yahoo.com> wrote
> However, is there an indentation error here?
Not that I can see. Is there an error? If so can you send the
traceback?
Its very hard to answer questions without any context.
> I may just be too frustrated to see it.
>
> for key in skeys:
> fracmiss=1.*numberMissing(z[key].values())/nsites #note
> decimal multiplication, 1.*
This is a mess. Why have that long comment when all that's needed
is to add the zero?! (and some spaces to make it legible...)
fracmiss = 1.0 * numberMissing( z[key].values() ) / nsites
outstring = "%s has %4.1f%% missing" % (key, 100 * fracmiss)
if fracmiss > 0.0:
print outstring
It looks OK apart from the poor style but I don't see anything that is
an error. What are you seeing?
On the style front, if you want to force a result to a float it's more
conventional to use the float() conversion function:
fracmiss = float( numberMissing( z[key].values() ) / nsites )
And comparing to 0.0 doesn't really add anything except two
characters,
it could just as well be plain old 0.
if fracmiss > 0:
HTH,
Alan G.
More information about the Tutor
mailing list