Strategy/ Advice for How to Best Attack this Problem?

Dave Angel davea at
Fri Apr 3 22:21:11 CEST 2015

On 04/03/2015 08:50 AM, Saran A wrote:
> On Friday, April 3, 2015 at 8:05:14 AM UTC-4, Dave Angel wrote:
>> On 04/02/2015 07:43 PM, Saran A wrote:
> I addressed most of the issues. I do admit that, as a novice, I feel beholden to the computer - hence the over-engineering.

Should be quite the opposite.  As a novice, you ought to be testing the 
heck out of your functions, worrying about whether they are properly 
named, properly commented, and properly tested.

 >>>       os.mkdir('Success')

> As you correctly stated:
> "
>> What do you do the second time through this function, when that
>> directory is already existing?
>>>       copy_and_move_file( 'Failure')
>> The function takes two arguments, neither of which is likely to be that
>> string.
>>>       initialize_logger('rootdir/Failure')
>>>       logging.error("Either this file is empty or there are no lines")"
> How would I ensure that this s directory is made only once and every file that is passeed goes only to 'success' or 'failure'?

Well, you could use an if clause checking with os.exist().  If the 
directory already exists, don't call the mkdir function.  That may not 
be perfect, but it should suffice for an assignment at your level.

Alternatively, you could set a global variable equal to 'Failure' or 
whatever the full path to the directory is going to be, and do a mkdir 
at the beginning of main().   Likewise for success directory, and the 
output text file.  In that case, of course, instead of creating the 
directory, you open the file (for append, of course, so the next run of 
the program doesn't trash the file), and keep the file handle handy.


More information about the Python-list mailing list