newbie question about event based programming
Alex Martelli
aleax at aleax.it
Mon Apr 8 06:24:59 EDT 2002
ashimali at btinternet.com wrote:
> Hello All,
> I'm wondering if there is a way to put an "event listener" (sorry for the
> Java terminology), on a directory. What I'm trying to do is have a python
> script be invoked on files whenever new file/s are copied/moved to a
> particular directory. Any tips gratefully recieved! Cheers Adam
That depends, first of all, on the functionality of your underlying
operating system -- for example, Windows lets you do that (if your
event loop is coded in a powerful enough way, but that's another
issue). I don't believe there is any cross-platform way -- it's not
up to the language, alas. The best you can achieve in most platforms
would be to "poll", say every second, to see if the directory was
modified. Even just getting a function of yours called every second
is hard to arrange in a cross-platform way. Fine if you're using
some given GUI toolkit, such as Tkinter (it has an .after method to
schedule a function call, and you need to call it again in the
scheduled function to get periodic repetitions), but there's no way
that works across platforms and toolkits.
Event-driven programming is a great thing, but it's not supported
as well as it could and should be across every platform and toolkit
in the world:-(.
Alex
More information about the Python-list
mailing list