View Single Post
Old Dec 10th, 2005, 2:19 PM   #1
UnKnown X
Hobbyist Programmer
 
UnKnown X's Avatar
 
Join Date: Dec 2005
Location: Sandvika, Norway
Posts: 114
Rep Power: 0 UnKnown X is an unknown quantity at this point
Send a message via MSN to UnKnown X
Reading numbers from file

I read ColdDeath's (brilliant ) tutorial, and decided to give Python a shot. So I made a programme that finds a Fibonacci number a few hours ago. Then I decided to come back and try to make it read from and write the results to a file.

Now, I can't figure out how to make it read the last number! The numbers are saved like this:
1
1
2
3
5
8
13
21
34
55
and so on (including the last newline)


I tried this, but it didn't work. I'm not sure where or why it fails:
        k = 1
        while (f.seek(k * -1, 2)) != '\n':
            k += 1
        k -= 1
        f.seek((f.read())-(f.read()-k))
        b = int(f.read((f.read())-(f.read()-k)))
        k += 2
        while (f.seek(k * -1, 2)) != '\n':
            k += 1
        k -= 1
        f.seek((f.read())-(f.read()-k))
        a = int(f.read((f.read())-(f.read()-k)))
        f.seek(0, 2)
UnKnown X is offline   Reply With Quote