从命令行调用python脚本而不输入“python”第一 [英] Calling a python script from command line without typing "python" first

查看:170
本文介绍了从命令行调用python脚本而不输入“python”第一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:在命令行中,如何调用python脚本而不必在脚本名称前键入 python ?这是可能吗?

Question: In command line, how do I call a python script without having to type python in front of the script's name? Is this even possible?

信息:

一个方便的脚本从命令行访问sqlite数据库,但我不喜欢必须键入python SQLsap args,而只是键入SQLsap args。我不知道这是否是可能的,但它是好的知道如果它是。

I wrote a handy script for accessing sqlite databases from command line, but I kind of don't like having to type "python SQLsap args" and would rather just type "SQLsap args". I don't know if this is even possible, but it would be good to know if it is. For more than just this program.

推荐答案

您可以在脚本的第一行预先添加一个shebang:

You can prepend a shebang on the first line of the script:

#!/usr/bin/env python

这将告诉你当前shell哪个命令将脚本输入。

This will tell your current shell which command to feed the script into.

这篇关于从命令行调用python脚本而不输入“python”第一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆