库中的某些函数在 python shell 中有效,但在脚本中无效

Some functions from library works in python shell but not in a script

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

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 上的文档报告 "Some environments don't support all 1-Line arts",但是它们在同一台机器上是相同的 python 版本。是否有环境的其他部分可能是原因?

在 shell 中它是隐式打印的...在脚本中您必须显式

print(randart())

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

from art import * 
print(randart())