本文介绍了Shebang或Hashbang的模块与否?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 不打算执行的Python模块是否应该使用shebang / hashbang(例如,#!/ usr / bin / env python)?我习惯在每个.py文件中都有一个 shebang,但是我最近听到有人认为 shebangs只适用于那些意图是 可执行文件(即从命令行运行)。 解决方案 如果你不打算让模块可执行,那么添加一个shebang 行和/或设置文件执行位是两者都违背 预定用途。因此,您应该省略shebang /不设置 执行位以强调您的预期用途。 在开发过程中,预期用途可能与使用时不同 已部署。 - Paddy。 shebang仅对您想要直接制作的文件有用 可执行* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *它们在Windows上没用,而且在技术上不需要使用该文件作为主程序-b:你可以 总是像这样运行: 编码声明可能更有用恕我直言! - ) 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 ashebang in every .py file but I recently heard someone argue thatshebangs were only appropriate for Python code intended to beexecutable (i.e., run from the command line). 解决方案 If you don''t intend the module to be executable then adding a shebangline and/or setting the files execute bit are both contrary tointended use. You should therefore leave out the shebang/not set theexecute bit to emphasise your intended use.During development however, intended use may differ from use whendeployed. - Paddy. The shebang is only useful for files that you want to make directlyexecutable on a *n*x system. They are useless on Windows, and nottechnically required to use the file as a main program -ie: you canalways run it like this:An encoding declaration might be more useful IMHO !-) 这篇关于Shebang或Hashbang的模块与否?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-10 13:30