运行旧版本脚本的python3

时间:2019-03-06 03:51:26

标签: python linux

我已通过注释掉一个部分并在其上方添加一些打印语句以进行测试来更改脚本,问题是当我从所在目录之外的任何其他目录运行脚本时,python正在运行旧版本的剧本。 清除__pycache__无效。

这是有问题的python脚本:

import discord
import watson
import configparser
import os
from discord.ext.commands import Bot
from getpass import getuser

print("WHY ISN'T THIS BEING CALLED!!")

#print(os.getcwd())
#os.chdir("/home/{}/discordBotStaging".format(getuser()))
#print(os.getcwd())

#if(not os.path.isfile("./config.ini")):
#    print("No config file found, make sure you have one in the same directory as this python script\nexiting")
#    quit()

config = configparser.ConfigParser()
config.read("./config.ini")

TOKEN = config["DEFAULT"]["DISCORD_KEY"]
BOT_PREFIX = ("!", "$")

client = Bot(command_prefix=BOT_PREFIX)

@client.command(name="memealyze",
        description="When uploading image include command \"!memealyze\" | \"!Memealyze\" | \"!MemeAlyze\" | \"!ma\" as a comment",
        brief="Neural network put to good use",
        aliases=["Memealyze", "MemeAlyze", "ma"],
        pass_context=True)

async def GetMemeContents(context):
    await client.say("Sending image to the mothership, hold tight.")

    if(not context.message.attachments):
        await client.say(
                "Couldn't find image attachement. Make sure you include \"!memealyze\" or any of it's variants as a comment when submitting an image")
        return

    imageUrl = str(context.message.attachments[0]["url"])
    messageContent = ""
    resultDict = watson.ReturnWatsonResults(imageUrl)

    for key,val in resultDict.items():
        messageContent += "{} : {}%\n".format(key, val)

    await client.say("Done, the boys at IBM said they found this:\n" + messageContent)

client.run(TOKEN)

这是问题所在

yugnut@RyzenBuild:~$ python3 discordBotStaging/main.py
No config file found, make sure you have one in the same directory as this python script
exiting
yugnut@RyzenBuild:~$

yugnut@RyzenBuild:~/discordBotStaging$ python3 main.py
WHY ISN'T THIS BEING CALLED!!
^Cyugnut@RyzenBuild:~/discordBotStaging$

编辑:

@ShadowRanger建议:

  

尝试将打印内容移到脚本中所有导入上方。

这会产生令人鼓舞的结果,我通过尝试确实得到了输出,但是此后我仍然遇到相同的问题

  

如果期望配置文件与脚本位于同一目录,则不能使用类似的相对路径;您必须做config.read(os.path.join(os.path.dirname(__file__), 'config.ini'))

我认为我的无知正在显示:^),我也在脚本中更改了

在进行了这些编辑并在注释掉import configparser行之后尝试运行脚本之后,我仍然遇到相同的错误。

0 个答案:

没有答案