Automatic debugging of copy by reference errors?
Niels L Ellegaard
niels.ellegaard at gmail.com
Sat Dec 9 07:08:14 EST 2006
Gabriel Genellina wrote:
> I think you got in trouble with something and you're trying to avoid it
> again - but perhaps this is not the right way. Could you provide some
> example?
I have been using scipy for some time now, but in the beginning I made
a few mistakes with copying by reference. The following example is
exagerated
for clarity, but the principle is the same:
import os
output=[]
firstlines =[0,0]
for filename in os.listdir('.'):
try:
firstlines[0] = open(filename,"r").readlines()[0]
firstlines[1] = open(filename,"r").readlines()[1]
output.append((filename,firstlines))
except:continue
print output
Now some of my fortran-using friends would like to use python to
analyze their data files. I wanted them to avoid making the same
mistakes as I did so I thought it would be good if they could get some
nanny-like warnings saying: "Watch out young man. If do this, then
python will behave differently from fortran and matlab". That could
teach them to do things the right way.
I am not an expert on all this, but I guessed that it would be possible
to make a set of constraints that could catch a fair deal of simple
errors such as the one above, but still allow for quite a bit of
programming.
Niels
More information about the Python-list
mailing list