Question: ```
def ints(filename):
    a = []
    f = open(filename, "r")
    lines = f.readlines()
    f.close()
    for line in lines:
        numbers = line.split()
        for number in numbers:            
            a.append(int(number))
    return a

```

This is my function so far, I want to be able to read a file containing integers and characters like "x" and "b" etc and return a list of only the integers. At the moment the function can only deal with a file containing integers.

How can I modify this to exclude characters or letters?

Answer: 
I just simply tested if characters were numbers:

```
sample_string = "Test4. 2325This string3"
a_list = []
for x in sample_string:
    if x.isdigit():
        a_list.append(x)

```
This is untested sudo-code, but should be valid. Also the best advice I can give is watch David Beazley's Generator Tricks for Systems programmers and Mastering Python 3 I/O talks. They were a great help in learning python.

This is just a simple generator to fetch each line of a file and close the file afterwards.

```
def getLine(fileName):
    file = open(fileName, "r")

    for line in file.readLines():
        yield line

    file.close()

def getNumbers(line):
// I'm lazy and stole this one from Keith
    for number in line.split():
        try:
            yield int(number)
        except ValueError:
            pass

def generatorChain(fileName):
    // I'm a little iffy on the syntax here, but shouldn't be to hard with a bit of googling
    fileGen = getLine(fileName);
    yield getNumber( fileGen.next() ).next()

def listCompressionMagic():
    return [x for x in generatorChain("foo.txt") ]

```