[Tutor] a few question about my evolving program
crk at godblessthe.us
Wed Aug 12 19:54:30 CEST 2015
> -----Original Message-----
> From: Tutor [mailto:tutor-bounces+crk=godblessthe.us at python.org] On
> Behalf Of Alan Gauld
> Sent: Wednesday, August 12, 2015 2:41 AM
> To: tutor at python.org
> Subject: Re: [Tutor] a few question about my evolving program
> On 12/08/15 04:23, Clayton Kirkwood wrote:
> > Question 2:
> > My current code:
> > See "Look here" below.
> If I understand your 'question', your code *should* reduce to this for the
> given filename:
> > target_directory_file_list =
> > master_directory_file_list[target_directory]
> > for current_directory_path in master_directory_file_list.keys():
> > current_file_list =
> > master_directory_file_list[current_directory_path]
> > for current_filename in current_file_list:
> > if current_filename in target_directory_file_list:
> Now, what is your expected output?
> And what are you getting?
> I'm not sure I understand what Question 2 actually is...
Given the data provided one could see that the current_filename, blah.jpg
didn't exist in the important target_directory_file_list of a.jpg, b.jpg,
Yet the next line of code is executed.
> > As you can see the current_filename does not exist in
> > target_directory_file list. Yet, I fall through to the next line.
> What does fall through mean? Which line do you fall through to?
> > Yes, the indents are all fine: I
> > wouldn't have gotten to running code otherwise.
> Running code does not mean correct code. The indents could all align with
> something but not necessarily what you want them to align with. However, I
> can't tell since I'm not sure what is actually going on yet.
> > I turned my head upside
> > down and still couldn't see why it doesn't work
> I doubt if that would help :-)
> What might help is breaking the code into say 3 helper functions That
> leave the higher level structure clear to see.
> Also, although we normally ask for 'meaningful variable names'
> yours are very long which actually makes the code harder to read.
> You could consider shortening some of them, especially those only used
> within a loop such as current_.... Just dropping the "current_" would
> doesn't really add any extra information. Similarly we know that paths are
> made up of directories so just path instead of directory_path probably
> works. (Use file_path to explicitly call out file paths if you must - its
> As an example consider my shortened code above using shorter names:
> target_file_list = master_directory_file_list[target_directory]
> > for path in master_directory_file_list.keys():
> > files = master_directory_file_list[path]
> > for name in files:
> > if name in target_file_list:
> Notice I kept the long name for the master list because it is used in
> segments. But those only used in the local loop are implicitly current and
> short lived so you don't need a long name.
> Readability is the first step to finding bugs and although your long names
> seem more descriptive their length actually gets in the way of reading the
> code structure easily.
> IMHO at least... :-)
> Alan G
> Author of the Learn to Program web site
> Follow my photo-blog on Flickr at:
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
More information about the Tutor