如何使用 python 修改文件时执行一些代码?

发布于 2024-08-20 23:41:53 字数 63 浏览 14 评论 0原文

我想在每次用新数据写入文件(修改)时执行一个函数,并且我使用的是 Python。

我该怎么做呢?

I want to execute one function each time a file gets written with new data (gets modified) and I'm using Python.

How can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥醉 2024-08-27 23:41:53

如果您想使用 Python 监视文件系统中的更改,请参阅 这篇文章提供了一些库的指针,可以帮助您在不同的平台上实现这一目标。

适用于不同平台的可用库的简短摘要:

请记住,您的程序需要运行才能处理文件系统事件。

If you want to monitor for changes in the file system using Python, see this article for pointers to libraries which can help you achieve this on different platforms.

Short summary of available libraries for different platforms:

Remember that your program needs to be running to handle file system events.

魂牵梦绕锁你心扉 2024-08-27 23:41:53

我假设不一定是您的 Python 程序正在修改该文件。我不知道是否有独立于操作系统的方法。在 Linux 上,您可以使用 pyinotify

I'm assuming that it's not necessarily your Python program that's modifying the file. I don't know if there's an OS-independent method. On Linux you can use pyinotify.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文