<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def foreach(self, argv, func):
 """Apply the function to each index named in the argument vector."""

        opts = cmdline(argv)
        if len(opts.args) == 0:
            error("Command requires an index name", 2)
        for name in opts.args:
            if name not in self.service.indexes:
                error("Index '%s' does not exist" % name, 2)
            index = self.service.indexes[name]
            func(index)