Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #88381

Re: Strategy/ Advice for How to Best Attack this Problem?

Date 2015-03-31 09:19 -0400
From Dave Angel <davea@davea.name>
Subject Re: Strategy/ Advice for How to Best Attack this Problem?
References (1 earlier) <87a8yvs34u.fsf@jester.gateway.pace.com> <mailman.323.1427681070.10327.python-list@python.org> <bc19cb8e-9e4f-48a7-a9f5-4b39db09a7ce@googlegroups.com> <mailman.344.1427740538.10327.python-list@python.org> <0623f75c-bf93-4a0f-9d87-86986185cdc3@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.371.1427807964.10327.python-list@python.org> (permalink)

Show all headers | View raw


On 03/31/2015 07:00 AM, Saran A wrote:

 > @DaveA: This is a homework assignment. .... Is it possible that you 
could provide me with some snippets or guidance on where to place your 
suggestions (for your TO DOs 2,3,4,5)?
 >


> On Monday, March 30, 2015 at 2:36:02 PM UTC-4, Dave Angel wrote:

>>
>> It's missing a number of your requirements.  But it's a start.
>>
>> If it were my file, I'd have a TODO comment at the bottom stating known
>> changes that are needed.  In it, I'd mention:
>>
>> 1) your present code is assuming all filenames come directly from the
>> commandline.  No searching of a directory.
>>
>> 2) your present code does not move any files to success or failure
>> directories
>>

In function validate_files()
Just after the line
                 print('success with %s on %d reco...
you could move the file, using shutil.  Likewise after the failure print.

>> 3) your present code doesn't calculate or write to a text file any
>> statistics.

You successfully print to sys.stderr.  So you could print to some other 
file in the exact same way.

>>
>> 4) your present code runs once through the names, and terminates.  It
>> doesn't "monitor" anything.

Make a new function, perhaps called main(), with a loop that calls 
validate_files(), with a sleep after each pass.  Of course, unless you 
fix TODO#1, that'll keep looking for the same files.  No harm in that if 
that's the spec, since you moved the earlier versions of the files.

But if you want to "monitor" the directory, let the directory name be 
the argument to main, and let main do a dirlist each time through the 
loop, and pass the corresponding list to validate_files.

>>
>> 5) your present code doesn't check for zero-length files
>>

In validate_and_process_data(), instead of checking filesize against 
ftell, check it against zero.

>> I'd also wonder why you bother checking whether the
>> os.path.getsize(file) function returns the same value as the os.SEEK_END
>> and ftell() code does.  Is it that you don't trust the library?  Or that
>> you have to run on Windows, where the line-ending logic can change the
>> apparent file size?
>>
>> I notice you're not specifying a file mode on the open.  So in Python 3,
>> your sizes are going to be specified in unicode characters after
>> decoding.  Is that what the spec says?  It's probably safer to
>> explicitly specify the mode (and the file encoding if you're in text).
>>
>> I see you call strip() before comparing the length.  Could there ever be
>> leading or trailing whitespace that's significant?  Is that the actual
>> specification of line size?
>>
>> --
>> DaveA
>
>

> I ask this because I have been searching fruitlessly through for some time and there are so many permutations that I am bamboozled by which is considered best practice.
>
> Moreover, as to the other comments, those are too specific. The scope of the assignment is very limited, but I am learning what I need to look out or ask questions regarding specs - in the future.
>


-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Strategy/ Advice for How to Best Attack this Problem? Saran Ahluwalia <ahlusar.ahluwalia@gmail.com> - 2015-03-29 04:32 -0700
  Addendum to Strategy/ Advice for How to Best Attack this Problem? Saran Ahluwalia <ahlusar.ahluwalia@gmail.com> - 2015-03-29 04:37 -0700
    Re: Addendum to Strategy/ Advice for How to Best Attack this Problem? Peter Otten <__peter__@web.de> - 2015-03-29 14:33 +0200
      Re: Addendum to Strategy/ Advice for How to Best Attack this Problem? Saran A <ahlusar.ahluwalia@gmail.com> - 2015-03-29 05:41 -0700
      Re: Addendum to Strategy/ Advice for How to Best Attack this Problem? Saran A <ahlusar.ahluwalia@gmail.com> - 2015-04-01 07:17 -0700
    Re: Addendum to Strategy/ Advice for How to Best Attack this Problem? Dave Angel <davea@davea.name> - 2015-03-29 09:27 -0400
  Re: Strategy/ Advice for How to Best Attack this Problem? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-03-29 19:00 -0400
  Re: Strategy/ Advice for How to Best Attack this Problem? Paul Rubin <no.email@nospam.invalid> - 2015-03-29 18:08 -0700
    Re: Strategy/ Advice for How to Best Attack this Problem? Chris Angelico <rosuav@gmail.com> - 2015-03-30 13:04 +1100
      Re: Strategy/ Advice for How to Best Attack this Problem? Saran A <ahlusar.ahluwalia@gmail.com> - 2015-03-30 09:45 -0700
        Re: Strategy/ Advice for How to Best Attack this Problem? Dave Angel <davea@davea.name> - 2015-03-30 14:35 -0400
          Re: Strategy/ Advice for How to Best Attack this Problem? Saran A <ahlusar.ahluwalia@gmail.com> - 2015-03-31 04:00 -0700
            Re: Strategy/ Advice for How to Best Attack this Problem? Dave Angel <davea@davea.name> - 2015-03-31 09:19 -0400
              Re: Strategy/ Advice for How to Best Attack this Problem? Saran A <ahlusar.ahluwalia@gmail.com> - 2015-04-01 06:43 -0700
                Re: Strategy/ Advice for How to Best Attack this Problem? Dave Angel <davea@davea.name> - 2015-04-01 19:51 -0400
                Re: Strategy/ Advice for How to Best Attack this Problem? Saran A <ahlusar.ahluwalia@gmail.com> - 2015-04-02 06:06 -0700
                Re: Strategy/ Advice for How to Best Attack this Problem? Dave Angel <davea@davea.name> - 2015-04-02 17:10 -0400
                Re: Strategy/ Advice for How to Best Attack this Problem? Saran A <ahlusar.ahluwalia@gmail.com> - 2015-04-02 16:43 -0700
                Re: Strategy/ Advice for How to Best Attack this Problem? Peter Otten <__peter__@web.de> - 2015-04-03 12:45 +0200
                Re: Strategy/ Advice for How to Best Attack this Problem? Saran A <ahlusar.ahluwalia@gmail.com> - 2015-04-03 06:40 -0700
                Re: Strategy/ Advice for How to Best Attack this Problem? Dave Angel <d@davea.name> - 2015-04-03 07:59 -0400
                Re: Strategy/ Advice for How to Best Attack this Problem? Saran A <ahlusar.ahluwalia@gmail.com> - 2015-04-03 05:50 -0700
                Re: Strategy/ Advice for How to Best Attack this Problem? Dave Angel <davea@davea.name> - 2015-04-03 16:21 -0400
                Re: Strategy/ Advice for How to Best Attack this Problem? Rustom Mody <rustompmody@gmail.com> - 2015-04-03 19:16 -0700

csiph-web