Visual Studio 模板参数:机器名称大写吗?
是 < code>$machinename$ 总是大写? 我想根据这个返回值编写一些代码,但是 Python 的 socket.gethostname()
返回“Mark-PC”,而 < code>$machinename$ 返回“MARK-PC”。如果是这样,我只需 .upper()
主机名,但我必须这样做似乎有点愚蠢。为什么不一致?
Is $machinename$
always capitalized? I wanted to write some code based on this return value, but Python's socket.gethostname()
returns "Mark-PC" whereas $machinename$
returns "MARK-PC". If so, I'll just .upper()
the hostname, but it seems kinda dumb that I should have to do this. Why the inconsistency?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
区别在于 $machinename$ 返回 NetBIOS 名称,而 socket.gethostname() 返回主机名。尽管 Windows 通常将它们命名为相同,但它们是不同的东西。从技术上讲,如果您更改 Windows 系统设置中的主 DNS 后缀,主机名 API 可能会返回不同的结果。 (此时它将是机器名称 + 后缀)
这是系统级别的,并非特定于 python,如等效的 C# API 所示:
The difference is that $machinename$ returns the NetBIOS name, and socket.gethostname() returns the host name. They are different things even though Windows usually names them identically. The host name API can technically return a different result if you change the Primary DNS suffix in your Windows system settings. (At which point it will be machine name + the suffix)
This is system level and not specific to python as illustrated by the equivalent C# APIs: