当我们需要 chmod +x file.py
我编写了一个 py 脚本来从网络获取页面,它只是足够的读写权限,所以我的问题是我们什么时候需要执行权限?
i wrote a py script to fetch page from web,it just read write permission enough,so my question is when we need execute permission?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想通过输入 python file.py 来运行它,读/写就足够了。如果您想像编译程序一样直接运行它,例如
./file.py
,那么您需要执行权限(以及顶部相应的 hash-bang 行)。Read/write is enough if you want to run it by typing
python file.py
. If you want to run it directly as if it were a compiled program, e.g../file.py
, then you need execute permission (and the appropriate hash-bang line at the top).如果您需要以这种方式运行脚本,则需要这样做:
./file.py
。但请记住,您需要将 python 的路径放在脚本的最顶部:#!/usr/bin/python
。但是等等,您需要确保拥有正确的路径,才能执行:
which python
。It's required to do so if you need to run the script in this way:
./file.py
. Keep in mind though, you need to put the path of python at the very top of the script:#!/usr/bin/python
.But wait, you need to make sure you have the proper path, to do that execute:
which python
.如果您希望能够直接使用
$ file.py
运行它,那么您需要设置执行位。否则,您可以使用$ python file.py
运行它。If you want to be able to run it directly with
$ file.py
then you'll need the execute bit set. Otherwise you can run it with$ python file.py
.