Re: Class data being zapped by method



Inline

1.) Why are you removing the .pyc file?

After I had run the script once and subsequently changed the class
file, I would run the script again, and it would use the pyc file from
the older revision of the script. I got frustrated with having to
manually delete the pyc file before rerunning the script after every
edit, so I built it in.

2.) Reading lines from a file is better done like so:

arrLines = open('datafiles/'+filename+'.tabdata').readlines()

and the 'r' flag is the default, you can omit it.

I know. In fact, this was the original code. However, I have read in
many places that if the file is *massive*, which is true in my case, it
is far more efficient to use the line-by-line implicit method I used.
On a decent machine it doesn't really make a noticeable difference, but
some of the ".tabdata" files I'm parsing are > 20MB plain text, so I
figured that warranted the alternative approach.

3.) You can create the Test instances like so:

arrTests = [Test() for i in range(cntTests)]

Figures. I'm overzealous with the list comprehensions below, and
totally ignorant of them here...

4.) You don't need "saveout = sys.stdout", sys.__stdout__ is already
this.

Cool.

5.) In "check = 0.6 * float(depth)" the call to float is redundant and
can be eliminated.

Understood.

6.) In "sumx = sum([x[0] for x in self.data])", etc.. you can leave out
the []'s. There's no need to create a list, the ()'s in the call to
sum() suffice to make a generator comprehension.

That I didn't know, and I'm glad I do now.


FWIW, if you're still having trouble later I'll try to take another
look at your code. Print statements and debuggers are your friends,
and John Machin's advice seems good to me.

Peace,
~Simon

Thanks to John M's debugging code I was led to the source of my
problems, or so it seems.

I'll post a follow up from work tomorrow (EDT) stating whether or not
the issue has been completely resolved.

Thank you both very much.

Aside --

John M, I realized what you meant about splitting the code between the
class and the processing file. At first it seemed intuitive, but
stepping back, it doesn't really make sense that a test would be able
to analyze and take an inventory of *itself*. I think I'm going to
reorganize the code such that the Test class does nothing but provide a
barebones data structure with which to work.

And regarding the file separation, it's totally personal preference. It
scales well, at least.

Another Aside --

Does anybody see any major bottlenecks in the code? I'd like to be able
to speed up the program considerably. Psyco was really no help.

Again, thanks

.



Relevant Pages

  • Re: Class data being zapped by method
    ... After I had run the script once and subsequently changed the class ... file, I would run the script again, and it would use the pyc file from ... barebones data structure with which to work. ... scales well, at least. ...
    (comp.lang.python)
  • Re: Class data being zapped by method
    ... John Machin wrote: ... After I had run the script once and subsequently changed the class ... file, I would run the script again, and it would use the pyc file from ... scales well, at least. ...
    (comp.lang.python)
  • Re: How did I screw this up?
    ... Initially what happened is that the 'import random' chose your script ... name as a builtin library you want to use. ... Python imports a module, and the .py file is newer than the .pyc file. ...
    (comp.lang.python)
  • Re: Location of Python modules
    ... then you should use distutils module and create a setup.py script ... the compiled bytecode (.pyc file) is always automatically generated ...
    (comp.lang.python)
  • Re: Roadshows, Part V
    ... each of the "skits" with John and Miles, there was a part where Miles ... script with cues for the lights and sound folks. ... "Listen, you know I really dig that Priscilla chick, right?" ...
    (soc.religion.mormon)