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.
In Python, everything is an object, including classes, modules and, yes, functions (and methods, which are just thin wrappers around functions). So you can do with a function whatever you can do with any other object : pass it to another function (or method), store it as an instance attribute, etc.

Your question seriously looks like homework so I won't give you a full-blown example (SO is not a do-my-homework service), but you'll learn most of what you need to know about this first point in the [FineManual(tm)](https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes) (nb: this is the Python3 manual, switch to the Python2 one if you use Python 2.x).

wrt/ your second question - reading a file - the doc is [here](https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files) (idem, Pyton3 version).

This should be enough to get you started.