jeudi 23 avril 2015

Returning variable outside function

I'm trying to work out how many lines of metadata there are until the real data starts, and the defined function below doesn't return the x value later on.

Why is x not defined outside the function? Is return x placed wrong?

def find(): 
    data=file('file.dat')
    x=0
    for line in data:
        if 'metaend' in line:
            break
            return x
        else:
            x+=1
find()

Aucun commentaire:

Enregistrer un commentaire