可执行文件的运行方式取决于它的启动位置

时间:2016-04-04 08:25:43

标签: python-2.7 cmd executable

我用Python 2.7创建了一个游戏,并且在将其转换为可执行文件后运行它时遇到了一些问题。如果我通过cmd切换到目录,它允许我使用已应用的所有格式运行它,如下所示:

Working game

如果我选择通过简单地执行游戏来访问它,它似乎正在读取类中包含反斜杠颜色的不同实体作为字符串。

Not working game

提供信息的班级如下,

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'

通用代码如下所示:

print bcolors.FAIL + ("Try combining the cd command and room you want to enter") + bcolors.END 

1 个答案:

答案 0 :(得分:0)

If you are running Windows, you may need to install Ansicon. This link will probably be of use to you: Colorama for Python, Not returning colored print lines on Windows