English 中文(简体)
利用Deque。 充气作为功能动力
原标题:Using Deque.popleft as args for function

我正试图储存一份指挥清单,以在沙捞中用蒸.发射序列电缆。

我的职能“承诺”接受3项价值观; 指挥官、一名随行士兵和一名 b子等。 其定义如下。

def send_command(self, command, pause=0, wait=False):

www.un.org/Depts/DGACM/index_spanish.htm 我想做的是,而不是把这一职能称为:

send_command("A234", 5, True)

......

send_command("B4242")

因此,我能够在清单中储存指挥系统,并利用飞机功能来称我的职能。 这将使我能够做以下事情:

CommandList = deque(([ A234 , 5, True], [ B4242 ]))

......并使用频率(申请表)作为在清单中增加内容的一种方法,然后由我派任——共同职务。 然后,当需要时,我可以放弃名单上的新指挥(或像我法典的序列部分那样迅速这样做)。

我所挣扎的那部分实际上是using,即指挥官List.popleft,或作为我派任——共同职能的跳板名单的任何部分。 这似乎简单明了:

send_command(CommandList.popleft)

我确信这只是一个简单的问题,但我不能说是这样。

谁能帮助?

感谢你们。

纽约总部

最佳回答

也许你们需要这样的东西:

obj.send_command(*CommandList.popleft())

这就是说,叫.,把结果作为派发——通商的理由清单。 <代码>自 的论点表明,这是成员的职能,因此,你需要将其称作物体。

我在评论中写道,另一种方式是储存准备的职能,如:

def make_command(obj, *args, **kwargs):
    def f():
        obj.send_command(*args, **kwargs)
    return f

然后,你可以做些什么。

queue.append(make_command(obj,  ABC , whatever= else ))

之后执行:

command = queue.popleft()
command()
问题回答

放弃是正确的——你需要<代码>(<>>>>>来称这一功能,并且你需要<代码>*>,以解脱论点。 然而,没有必要使用<代码>deque。 当你能够做到这一点时:

commandlist = [[ A234 , 5, True], [ B4242 ], [ A234 , 0]]

for command in commandlist:
   send_command(*command)

这将完全奏效。 For more info, see un Packing debate list

如果你重新做你想要消耗这些价值的东西——说你想要你的指挥员在你回任时空洞的话,确实有必要问。 当然,你也可以用一份清单做同样的事情:

q = [1,2,3,4]
while q:
   print q.pop(0)
print q

HTH

您:

send_command(CommandList.popleft()) # note the ()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签