New to Programming: Adding custom functions with ipynotify classes

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Apr 3 13:37:29 CEST 2015


On Fri, 3 Apr 2015 12:30 pm, Saran A wrote:

> Hello All:
> 
> Here is the program that I am trying to write (with specs):
[...]

Do you have an actual question?

If you want a code review of your entire application, the polite thing to do
is to ask for volunteers first, before dropping 200+ lines of code on us.

If you have a specific question you would like to ask, then it is good to
focus on that issue alone, not your entire application. I see you say this:

> Many on forums suggest using ipynotify. I am wondering how to combine my
> current script and add it to the ipynotify.

Have you read the examples and followed the tutorial?

https://github.com/seb-m/pyinotify/wiki/List-of-Examples

https://github.com/seb-m/pyinotify/wiki/Tutorial


By the way, I have found at least one bug in your code:

> #This helper function returns the length of the file
> def file_len(f):
>     with open(f) as f:
>         for i, l in enumerate(f):
>             pass
>             return i + 1

Not as given it doesn't. It will raise an exception if the file cannot be
opened, and it will return 1 for any file you can read.

After you fix the incorrect indentation, the function is horribly
inefficient. Instead, use this:

import os
os.stat(filename).st_size





-- 
Steven




More information about the Python-list mailing list