문제

I'm using memory.py from fusepy (http://code.google.com/p/fusepy/source/browse/trunk/memory.py) for a programming assignment.

How does setxattr (line 87) actually accomplish anything? self.files isn't modified in any way and attrs is destroyed when the function exits.

도움이 되었습니까?

해결책

def setxattr(self, path, name, value, options, position=0):
    # Ignore options
    attrs = self.files[path].setdefault('attrs', {})
    attrs[name] = value

The side-effect is achieved by setdefault, which creates a new item in self.files[path] (unless attrs already exists as a key in it), and returns a reference to the value.

Next, that reference is modified, by assigning to its key name, the value value. By that operation too, self.files is modified.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top