[英]How can i select a specific argument to handle using *args?
In my last question the answer helped me solve an issue of choosing Number
against other arguments. 在我的最后一个问题中 ,答案帮助我解决了选择
Number
反对其他论点的问题。
Then out of curiosity I though what if I actually had to use char2
or char1
or char3
etc.. without referring to a list that'll let me use them based on their placement in the argument. 然后出于好奇,虽然我实际上必须使用
char2
或char1
或char3
等。如果不参考允许我根据其在参数中的位置使用它们的列表,该怎么办。
The best way I could find after some research is creating a dynamic array for the arguments where each argument is an object in 1 class dedicated for that purpose, and actually separate them based on their object distinction. 经过研究后,我发现的最佳方法是为参数创建动态数组,其中每个参数都是专用于该目的的1类对象,并根据它们的对象区别实际上将它们分开。 That being said couldn't find any examples to clarify that method or walk me through the process step by step.
话虽如此,找不到任何示例来阐明该方法,也无法逐步引导我完成整个过程。
So I'd like to get ways on how to solve that issue and walking through the process. 因此,我想获得有关如何解决该问题并逐步完成该过程的方法。
So if I'm understanding you correctly: 因此,如果我正确地理解了您:
You want to pass char2,char1,char3
to your function and process this input not in terms of position, like you did with args, but in terms of "names". 您想将
char2,char1,char3
传递给函数,并且不像在args中那样在位置方面而是在“名称”方面处理此输入。 The solution are **kwargs
. 解决的办法是
**kwargs
。 What do they do ? 他们在做什么 ? A good Explanation might be given here .
这里可能给出一个很好的解释。
If this doesn't solve your problem or doesn't even fit for the question please clearyfy your question. 如果这不能解决您的问题或什至不适合该问题,请清除您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.