Question: I have a task what I should program in python. I should have a class named Tasks. I can do it by 

```
class Tasks:

```

code. This class should have 4 method, with one method needed to pass a logical function to it, go over all of the elements in a inF named file and then count the appropriate values in the inF file, and then should write it out. My question is that how can I define a function which parameter should be an another defined logical function?

Here is an example:
There is an another file which should call my Tasks class, for example name it "test". It has the following code:

```
def odd(x):
   if x % 2 != 0 : 
       return True
   else:
       return False

task = Tasks("in") //Here I have another problem as I don't know how can I open the file by just the Tasks' constructor. 
print task.count(odd)

```

Could you please provide me a solution for this? 

EDIT1:
If the inF file have the following values:

```
30
25
30
21
19

```

Then the task.count(odd) should print 3

Answer: 
There's nothing necessarily magical about a function's name, so you can pass a function as an argument, then invoke it with the argument name in the function.

For example, part of your solution might include

```
class Task:
    def count(self, func):
         with file(self.inF, "r") as src:
             return [x for x in src if func(x)]
         return []

```

though the function you pass to `count` in this example will have to expect a string that ends in `\n` or `\r\n` depending on the contents of the `inF` file.
Just give your function the other function and have it use it:

```
def count(boolfunc, things):
    counter = 0
    for thing in things:
        if boolfunc(thing):
            counter += 1
    return counter

```

Demo usage:

```
>>> count(odd, [30, 25, 30, 21, 19])
3

```

Though I just did that to show it more clearly. In reality I'd use Python's `filter` function:

```
def count(boolfunc, things):
    return len(filter(boolfunc, things))

```

Btw, that if-X-return-True-return-False always bugs me. I suggest using one of these instead:

```
def odd(x):
    return x % 2 != 0

def odd(x):
    return x % 2 == 1

def odd(x):
    return bool(x % 2)

def odd(x):
    return x % 2

```