Clayton Kirkwood wrote: > Good eyes on the logic > > > !-----Original Message----- > !From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On > !Behalf Of Peter Otten > !Sent: Sunday, October 26, 2014 3:53 AM > !To: tutor@python.org > !Subject: Re: [Tutor] if you're interested in the code thus far... > ! > !Clayton Kirkwood wrote: > ! > !> for description_position, code_position in zip(description, code): > !> description_position_len = len(description_position) > !> current_output_pos += description_position_len > !> if current_output_pos >= output_line_len: > !> print(description_output_string) > !> print(code_output_string) > !> code_output_string=description_output_string='' > !> current_output_pos=-1 #start new line > > Changing this line to current_ouput_pos = description_position_len > I believe I was losing the next lines final field on each subsequent line
There's no need to guess. Run the code with a small test dataset and compare the actual output with manually determined output. To make this approach feasible it is better to put the formatting algorithm into a function rather than to print() the lines directly. Here's a sketch: def format_output(pairs, width): ... # your code building lines from the pairs expected = [ "abc|de|", "x |y |", "1234567|" "z |" ] got = format_output([ ("abc", "x"), ("de", "y"), ("1234567", "z"), ], 9) if got != expected: print("expected", expected) print("got", got) raise AssertionError Once you start doing this for all your code you should have a look at https://docs.python.org/dev/library/unittest.html _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor