例如。正确的样本 -
f.write("\t" +connection_name+ "\t =" + qs.connection_name + "\n")
我想做什么-
f.write("\t" +current+ "\t=" +qs.current+ "\n")
//此处 current = 'connection_name'
如何以这种方式连接 - qs.current 以便打印为 qs.connection_name 的值
请您参考如下方法:
您可以使用 getattr
getattr(qs, current)
所以在你的代码上下文中
f.write("\t" + current + "\t=" + getattr(qs, current) + "\n")
