简体   繁体   English

从 shell 控制台手动运行 python3 脚本和命令

[英]Manually running python3 script and commands from shell console

https://github.com/dtcarls/ff_bot https://github.com/dtcarls/ff_bot/blob/master/ff_bot/ff_bot.py https://github.com/dtcarls/ff_bot https://github.com/dtcarls/ff_bot/blob/master/ff_bot/ff_bot.py

I am trying to figure out a way to manually have this python script run certain functions, like get_trophies from the terminal.我试图找出一种方法来手动让这个 python 脚本运行某些功能,比如从终端获取 get_trophies。 Currently the script is scheduled to send certain messages each week, at a specific time, but I would really like to be able to manually resend the message through the shell.目前,该脚本计划每周在特定时间发送某些消息,但我真的希望能够通过 shell 手动重新发送消息。

Something like "python3 ff_bot.py get_trophies" and have the bot send that message again.类似“python3 ff_bot.py get_trophies”之类的东西,让机器人再次发送该消息。

Not sure if this is possible, and I am very limited in my programming knowledge.不确定这是否可能,而且我的编程知识非常有限。 The app was auto deployed to heroku per the readme on GitHub该应用程序根据 GitHub 上的自述文件自动部署到 heroku

python -3 <script name> *args **kwargs 

Anything wrong with that?有什么问题吗?

If it's part of a module如果它是模块的一部分

python -3 -m module.script_name *args **kwargs

Alternatively you could do:或者你可以这样做:

from ff_bot import get_trophies

If you put that into your own .py file you will be able to use the function stand alone (providing you don't need to import other things too!)如果你把它放到你自己的 .py 文件中,你将能够独立使用该函数(前提是你不需要导入其他东西!)

HTH!哼!

If you are on Linux you can just use the command line to run the python script as you have described, if you are on Windows, and Python is in your path, you can double-click on the script to run it.如果你在 Linux 上,你可以像你描述的那样使用命令行运行 python 脚本,如果你在 Windows 上,并且 Python 在你的路径中,你可以双击脚本来运行它。 Beyond that, you just add the command line argument after the script name: python script.py arg1 arg2除此之外,您只需在脚本名称后添加命令行参数:python script.py arg1 arg2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM