赋值前引用的局部变量 'subprocess'

local variable 'subprocess' referenced before assignment

这是我的代码,我试图在命令行中执行命令并获取输出,但出现错误。请帮助我

import telebot
import subprocess


token = ''
bot = telebot.TeleBot(token)

@bot.message_handler(commands=['echo'])
def changeWall(message, res=True):
    subprocess = subprocess.Popen("echo Hello World", shell=True, stdout=subprocess.PIPE)
    subprocess_return = subprocess.stdout.read()
    print(subprocess_return)
    bot.reply_to(message, subprocess_return)

错误:

local variable 'subprocess' referenced before assignment

您需要更改 subprocess 变量的名称。

您可以在这里阅读更多内容:Python: function and variable with the same name

我还建议您从代码中删除令牌。