我想建立一个可变数量的参数记录器如下。我想这样称呼它:如何在Python打印内打印列表?
log(1, "Index: ", request_index, ", ", section)
def log(level, *msg) :
global print_debug_lastTime
currentTime = datetime.datetime.now().microsecond
# You can access global variables without the global keyword.
if g_debug_level & level != 0:
print("[DEBUG] " \
+ "%02d" % datetime.datetime.now().hour + ":" \
+ "%02d" % datetime.datetime.now().minute + ":" \
+ "%02d" % datetime.datetime.now().second + ":" \
+ str(currentTime) \
+ "%7d " % (currentTime - print_debug_lastTime) \
+ for m in msg)
但我无法打印可变数量的参数。起初我想在解释器中运行这个简单的代码:
>>> print(str(x) for x in (0,1,2,3))
<generator object <genexpr> at 0x6ffffe5e550>
我想它打印0123
,但它打印出来作为可能看起来。
那是因为你有什么打印里面是一个生成器表达式,所以你可以这样做:'print(list(str(x)for x in(0)) ,1,2,3)))'。 – idjaw
谢谢! 'print(“”.join([str(x)for(in(0,1,2,3)]))''做到了。 – user