不打算执行的Python模块是否应该使用shebang / hashbang(例如,#!/ usr / bin / env python)?我习惯在每个.py文件中都有一个 shebang,但是我最近听到有人认为 shebangs只适用于那些意图是 可执行文件(即从命令行运行)。
解决方案4月11日下午5:29, Chris Lasher < chris.las ... @ gmailwrote: 如果没有打算执行的Python模块有shebang / hashbang (例如,#!/ usr / bin / env python)或不?我习惯在每个.py文件中都有一个 shebang,但是我最近听到有人认为 shebangs只适用于那些意图是 可执行文件(即从命令行运行)。
如果你不打算让模块可执行,那么添加一个shebang 行和/或设置文件执行位是两者都违背 预定用途。因此,您应该省略shebang /不设置 执行位以强调您的预期用途。 在开发过程中,预期用途可能与使用时不同 已部署。 - Paddy。
Chris Lasheraécrit: 如果不打算执行的Python模块是否有shebang / hashbang(例如,#!/ usr / bin / env python)或不?
shebang仅对您想要直接制作的文件有用 可执行* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *它们在Windows上没用,而且在技术上不需要使用该文件作为主程序-b:你可以 总是像这样运行:
/ path / to / python filename.py 我习惯拥有 $ b $每个.py文件中的b shebang
编码声明可能更有用恕我直言! - )
Should a Python module not intended to be executed have shebang/ hashbang (e.g., "#!/usr/bin/env python") or not? I''m used to having a shebang in every .py file but I recently heard someone argue that shebangs were only appropriate for Python code intended to be executable (i.e., run from the command line).
解决方案 On Apr 11, 5:29 pm, "Chris Lasher" <chris.las...@gmailwrote: Should a Python module not intended to be executed have shebang/ hashbang (e.g., "#!/usr/bin/env python") or not? I''m used to having a shebang in every .py file but I recently heard someone argue that shebangs were only appropriate for Python code intended to be executable (i.e., run from the command line).If you don''t intend the module to be executable then adding a shebang line and/or setting the files execute bit are both contrary to intended use. You should therefore leave out the shebang/not set the execute bit to emphasise your intended use. During development however, intended use may differ from use when deployed. - Paddy.
Chris Lasher a écrit : Should a Python module not intended to be executed have shebang/ hashbang (e.g., "#!/usr/bin/env python") or not?The shebang is only useful for files that you want to make directly executable on a *n*x system. They are useless on Windows, and not technically required to use the file as a main program -ie: you can always run it like this:
/path/to/python filename.py I''m used to having a shebang in every .py fileAn encoding declaration might be more useful IMHO !-)
更多推荐
Shebang或Hashbang的模块与否?
发布评论