Python识别cygwin上的UNC路径
所有机器都在 Windows Server 2003 上。
如果我只在其中一台机器上安装 cygwin 并在其上运行我的 python 脚本来操作来自所有远程主机的文件。如何通过 UNC 路径访问这些文件?
All machines are on Windows Server 2003.
If I only install cygwin on one of the machine and run my python script on it to manipulate files from all remote hosts. How can I access to those files via UNC path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cygwin 理解使用两个正斜杠的 UNC 路径名(与 Windows 典型的两个反斜杠相反 - 事实上,在 Cygwin 下,您必须在路径中的任何位置使用正斜杠而不是反斜杠)。我假设这种支持将传播到在 Cygwin 之上运行的 Python,但我从未尝试过确认。
编辑:如果您不需要在 cygwin 下运行 python,正如您在评论中提到的那样,那么您为什么要这样做?只需从 python 下载站点 安装本机 Windows python,然后忘记 Cygwin。但是,您可能必须在路径名中使用双反斜杠,因为 IIRC Python 使用反斜杠作为转义字符,因此要在最终字符串中获得一个反斜杠,您需要输入两个反斜杠。
Cygwin understands UNC pathnames that use two forward slashes (as opposed to the two backslashes typical of Windows -- in fact, under Cygwin, you must use forward slashes instead of backslashes anywhere in the path). I assume that this support would be propagated through to Python running on top of Cygwin, but I haven't ever tried it to confirm.
Edit: if you don't need to run python under cygwin, as you mention in a comment, then why are you doing so? Just install the native windows python from the python download site and forget about Cygwin. You'll probably have to double your backslashes in the path names, however, since IIRC Python uses backslash as an escape character, so to get one backslash in the final string you need to put in two.