strange problem with def in class

Johan megalomaan at hotmail.com
Tue Aug 17 20:21:17 EDT 2004


I don't get it:
I'm trying to write a "readfile" function which would replace some code from
a __init__ function:

1    import string
2    class landdict:
3        def __init__(self, file):
4                # Laadt de dictionnary van landen.
5                # Kijk in de actiefspel-file voor de file van waaruit je
moet laden.
6                self.ld = {}
7                f = open(file, "r")
8                line = f.readline()
9                if line[0] == "#":
10                    line = f.readline()
11              while line != "":
12                    key = line[0:3]
13                    self.ld[key] = string.split(line[4:], ':')
14                    line = f.readline()
15              print self.ld

So I would like to replace the code from line 7 to line 14 with

readfile(filename)

while

def readfile(filename) is another function in the class

but I can't define this function.... when I call the function the
interpreter throws an exception of unknown function
what am I doing wrong?
-- 
____________________________________________________
Johan Potums
Vaartstraat 67
3000 Leuven

johan.potums at student.kuleuven.ac.be



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004





More information about the Python-list mailing list