首页 > 解决方案 > 库中的一些函数在 python shell 中工作,但不在脚本中

问题描述

我无法从名为 art ( https://github.com/sepandhaghighi/art ) 的库中获取某些函数以在脚本中运行,尽管它们在 shell 中运行良好。按顺序输入的脚本/命令如下所示:

from art import * randart() <(function fails in script, but succeeds in shell) tart("test") <(different function, same library, succeeds in both shell and script) import sys print(sys.version)

对于 shell 和脚本,python 版本都是 3.7.5。第一个函数在脚本中运行时不会抛出错误,但不会给出任何输出。它所需的输出是来自集合的随机 ascii_art。我觉得我错过了一些非常简单的东西。有任何想法吗?github 上的文档报告“某些环境不支持所有 1 线艺术”,但是它们是同一台机器上的相同 python 版本。环境的其他部分是否可能是原因?

标签: pythonpython-3.xpython-3.5

解决方案


您需要randart()在编写脚本时打印。养成print()在打印时使用所有内容的习惯。Shell 是默认返回值的地方,而您需要告诉脚本窗口如何处理任何名称或函数。所以用这个:

from art import * 
print(randart())

推荐阅读