gpt4 book ai didi

python - 在python中打印变量

转载 作者:太空宇宙 更新时间:2023-11-04 09:16:53 24 4
gpt4 key购买 nike

我有这个 python 代码,它在一个类中设置 A 或 B。我想打印这个类收到的内容:

if options.A:
print "setting A"
class TmpClass(A): pass
else:
print "nothing set in the command line => setting to B"
class TmpClass(B): pass

print "selected=",TmpClass

我想在输出中看到 A 或 B,但我看到了:

selected= TmpClass

最佳答案

你的代码在做什么,翻译成英文是:

if option.A has a value that evaluates to True:
define an empty class called "TmpClass" that inherits from the object called "A"
otherwise:
define an empty class called "TmpClass" that inherits from the object called "B"

现在,如果代码实际执行的确实是您想要的,我猜测是您想要知道您的类是 A 类还是 B -based...如果我是对的,那么你最后想要的那一行是:

print('TmpClass inherits from : %s' % TmpClass.__bases__)

喂!

关于python - 在python中打印变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8224341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com