"Adrian Graham" <aag at stanford.edu> wrote in message news:9aau45$3sf$1 at nntp.Stanford.EDU... > I'm in the process of writing a class based on a module that I have > previously written. The problem that I'm running across is that since "self" > is always the first argument to any function within a class, functions that > I have been using as callbacks no longer work since their signature has > changed to include self. > class FileManager: > > def __init__(self): > self.path = << some path >> > self.rs = << a record set >> > > def InsertDirectories(self): > os.path.walk(self.path, self.InsertDirectory, self.rs) > > def InsertDirectory(rs, dirname, names): > ... try making that def insertDirectory(self, rs, dirname, names): ... not that you actually need to pass rs, as you can get to it through self. > Unfortunately, I can't code it this way, since InsertDirectory's signature > is now: InsertDirectory(self, rs, dirname, names), which doesn't match > os.path.walk's callback signature. I know the easy (and inelegant) way to try it, you may be surprised ... since you pass self.insertDirectory to walk, the self parameter has already been bound ... making its signature exactly what you want. > I have the feeling that there is some elegant way to do what I want with > Python, but that my C++/Java experience is getting in the way. Any > suggestions?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4