python - Extend set to make custom set -


this new question because question.

i want extend set make custom set of file names in folder:

class filesset(set):      def __init__(self, in_dir = none):         set.__init__(self, ())          self.in_dir = ''         self.files = set()                  if in_dir:                     self.in_dir = in_dir                     self.files = set(map(os.path.basename,                               glob.glob(self.in_dir + "/*.txt")))       def __contains__(self, item):         return item in self.files      def __len__(self):         return len(self.files)      def __iter__(self):         return iter(self.files)      

when try it:

f1 = filesset(in_dir = indir1) f2 = filesset(in_dir = indir2)  c1 = f1 | f2 c2 = f1 & f2  print(c1, c2) 

c1 , c2 empty. why? should overwrite other methods set? link think need define contains, len , iter. other methods or(), sub(), xor() performance only, understand.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -