Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'output': 0.05; 'string.': 0.05; 'assignment': 0.07; 'arguments,': 0.09; 'clause': 0.09; 'friday,': 0.09; 'function,': 0.09; 'subject:How': 0.10; 'exists,': 0.16; 'likewise': 0.16; 'main().': 0.16; 'mkdir': 0.16; 'ought': 0.16; 'subject:Problem': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'properly': 0.19; '>>>': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'file.': 0.24; 'second': 0.26; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'testing': 0.29; 'am,': 0.29; "doesn't": 0.30; 'directory,': 0.31; 'file': 0.32; 'run': 0.32; 'quite': 0.32; 'text': 0.33; 'open': 0.33; 'beginning': 0.33; 'checking': 0.33; 'level.': 0.33; 'could': 0.34; 'case,': 0.35; 'equal': 0.35; 'but': 0.35; 'there': 0.35; 'next': 0.36; 'subject:?': 0.36; 'should': 0.36; 'two': 0.37; 'handle': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'ensure': 0.60; 'dave': 0.60; 'most': 0.60; 'full': 0.61; 'success': 0.61; 'charset:windows-1252': 0.65; 'received:74.208': 0.68; 'subject:this': 0.83; '2015': 0.84; 'angel': 0.91; 'subject:Best': 0.91 Date: Fri, 03 Apr 2015 16:21:11 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Strategy/ Advice for How to Best Attack this Problem? References: <87a8yvs34u.fsf@jester.gateway.pace.com> <0623f75c-bf93-4a0f-9d87-86986185cdc3@googlegroups.com> <4d3a3336-5dc1-4fe8-8ef6-1616c6629d01@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:8OMkiLpxVLEFhnUwBXj4OKRVf1rxycX+9GHp6leBKFwmWdAXBrr KphzW1/zgg4S5DgOsl3bHZP/YuR0Bm/rTctkqF3QNX60WCOsQnDjhY9LXvFOPCo7cWZZIcV d7J4hDQRMPf27+jQnibJBoWeFumiMKhfvakKQmN5I/rhed/IBZfqd118WqIWG2Z8aqIh1eB D8Rbuh9RexsuChGF5GW/A== X-UI-Out-Filterresults: notjunk:1; X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1428092476 news.xs4all.nl 2860 [2001:888:2000:d::a6]:46410 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88492 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. -- DaveA