Strategy/ Advice for How to Best Attack this Problem?

Saran A ahlusar.ahluwalia at gmail.com
Tue Mar 31 07:00:46 EDT 2015


On Monday, March 30, 2015 at 2:36:02 PM UTC-4, Dave Angel wrote:
> On 03/30/2015 12:45 PM, Saran A wrote:
> > On Sunday, March 29, 2015 at 10:04:45 PM UTC-4, Chris Angelico wrote:
> >> On Mon, Mar 30, 2015 at 12:08 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> >>> Saran Ahluwalia <ahlusar.ahluwalia at gmail.com> writes:
> >>>> cross-platform...
> >>>> * Monitors a folder for files that are dropped throughout the day
> >>>
> >>> I don't see a cross-platform way to do that other than by waking up and
> >>> scanning the folder every so often (once a minute, say).  The Linux way
> >>> is with inotify and there's a Python module for it (search terms: python
> >>> inotify).  There might be comparable but non-identical interfaces for
> >>> other platforms.
> >>
> >> All too often, "cross-platform" means probing for one option, then
> >> another, then another, and using whichever one you can. On Windows,
> >> there's FindFirstChangeNotification and ReadDirectoryChanges, which
> >> Tim Golden wrote about, and which I coded up into a teleporter for
> >> getting files out of a VM automatically:
> >>
> >> http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html
> >> https://github.com/Rosuav/shed/blob/master/senddir.py
> >>
> >> ChrisA
> >
> > @Dave, Chris, Paul and Dennis: Thank you for resources and the notes regarding what I should keep in mind. I have an initial commit: https://github.com/ahlusar1989/IntroToPython/blob/master/Project1WG_with_assumptions_and_comments.py
> >
> > I welcome your thoughts on this
> >
> 
> 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
> 
> 3) your present code doesn't calculate or write to a text file any 
> statistics.
> 
> 4) your present code runs once through the names, and terminates.  It 
> doesn't "monitor" anything.
> 
> 5) your present code doesn't check for zero-length files
> 
> 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

@ Dave A

On Monday, March 30, 2015 at 2:36:02 PM UTC-4, Dave Angel wrote:
> On 03/30/2015 12:45 PM, Saran A wrote:
> > On Sunday, March 29, 2015 at 10:04:45 PM UTC-4, Chris Angelico wrote:
> >> On Mon, Mar 30, 2015 at 12:08 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> >>> Saran Ahluwalia <ahlusar.ahluwalia at gmail.com> writes:
> >>>> cross-platform...
> >>>> * Monitors a folder for files that are dropped throughout the day
> >>>
> >>> I don't see a cross-platform way to do that other than by waking up and
> >>> scanning the folder every so often (once a minute, say).  The Linux way
> >>> is with inotify and there's a Python module for it (search terms: python
> >>> inotify).  There might be comparable but non-identical interfaces for
> >>> other platforms.
> >>
> >> All too often, "cross-platform" means probing for one option, then
> >> another, then another, and using whichever one you can. On Windows,
> >> there's FindFirstChangeNotification and ReadDirectoryChanges, which
> >> Tim Golden wrote about, and which I coded up into a teleporter for
> >> getting files out of a VM automatically:
> >>
> >> http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html
> >> https://github.com/Rosuav/shed/blob/master/senddir.py
> >>
> >> ChrisA
> >
> > @Dave, Chris, Paul and Dennis: Thank you for resources and the notes regarding what I should keep in mind. I have an initial commit: https://github.com/ahlusar1989/IntroToPython/blob/master/Project1WG_with_assumptions_and_comments.py
> >
> > I welcome your thoughts on this
> >
> 
> 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
> 
> 3) your present code doesn't calculate or write to a text file any 
> statistics.
> 
> 4) your present code runs once through the names, and terminates.  It 
> doesn't "monitor" anything.
> 
> 5) your present code doesn't check for zero-length files
> 
> 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


@DaveA: This is a homework assignment. As someone is not familiar (I have only been programming for 8 months) with best practice for writing to files, appending to folders and searching a directory. 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)?

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.



More information about the Python-list mailing list