[Tutor] Critiquing My Program

Kent Johnson kent37 at tds.net
Sun Oct 12 14:41:42 CEST 2008


On Sat, Oct 11, 2008 at 10:52 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Here's where the code resides <http://pastebin.com/mb02edf4>

OK, some comments:
- Track_data.get_data() should just be part of Track_data.__init__(),
there is no need for it to be separate and the Track_data is not
usable until get_data() is called.

- You asked about named attributes; Track_data instances themselves
have named attributes. Instead of returning the data as a list, use
the Track_data directly. Assuming you remove get_data() as suggested
above, you would use Track_data like this:
            line_data = Track_data(line)
            stats.sum(fields.amplitude, fields.cntrd_x, fields.cntrd_y)

You could also pass the Track_data instance directly to the Stats methods.

- Similarly, Stats.sum need not return a list, and Stats.get_sums() is
not needed; just access the Stats attributes directly.

- You could combine Stats.sum() and stats.collection() into one method.
- Stats.n_frames is redundant, it is the same as len(stats.xya)
- You could use glob.glob('v2*.txt') instead of os.listdir()

-     if (file[-3:] == 'txt') & (file[0:2] == "v2"):
Should be 'and' instead of '&'

Kent


More information about the Tutor mailing list