如何在具有 FileShare 权限的 Windows 上使用 Python 打开文件? [英] How to open a file with Python on Windows with FileShare permissions?

查看:33
本文介绍了如何在具有 FileShare 权限的 Windows 上使用 Python 打开文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过这个问题:即使正在被另一个进程使用",我如何读取文件?例外?是否有在 Windows 7 上使用 Python 执行此操作的等效方法?

I have seen this question: How can I read a file even when getting an "in use by another process" exception? Is there an equivalent way to do this using Python on Windows 7?

我需要修改一个文件,但仍然让其他进程在 Python 中打开它时读取它.根据 Python 文档,可用模式是r"、w"、a"和r+",分别代表读、写(覆盖)、追加和读/写.我看不到设置文件共享"模式的方法.

I need to modify a file but still let other processes read it while it's open in Python. The available modes, according to Python doc are "r","w","a",and "r+", which stand for read, write (overwrite), append, and read/write. I don't see a way to set "FileShare" modes.

推荐答案

如果您需要精细控制共享模式,可以使用 win32file.CreateFile 打开文件.ActiveState 文档位于此处.

If you need fine control over the sharing mode, you can use win32file.CreateFile to open the file. ActiveState docs are here.

这篇关于如何在具有 FileShare 权限的 Windows 上使用 Python 打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆