Can I hook a "file" to a python script?

Alex Martelli aleaxit at yahoo.com
Sat Nov 8 04:58:37 EST 2003


Scott Chapman wrote:

> I'd like a "file" on the Linux box to actually be the input and output
> of a Python script.  Anything written to the file would be sent to a
> database and anything read from the file would come from the database.
> I know how to do the database end of this but I'm not sure if a script
> can be hooked to a "file" transparently.  The script would probably
> have to be run as a daemon.  I doubt there's enough magic in the Linux
> world to make it so that a read/write would actually launch the script.

"named pipes", aka FIFOs (created by the mkfifo shell command) are
going to be the "files" you use for that.  But, yes, SOME daemon must
be watching on them, e.g. with a select -- could be a generic one that
will spawn the specific one at need, but it's simpler to have the real
script watch on them -- I do agree there's probably no way to get the
kernel to do it for you.


Alex





More information about the Python-list mailing list