shutil ignore fails on passing a tuple?

Alex van der Spek zdoor at xs4all.nl
Thu Jul 19 18:43:27 CEST 2012


This beats me:
++++++++++++++++++++
>>> ipatterns
('*.txt', '*.hdf', '*.pdf', '*.png')
>>> igf = shutil.ignore_patterns(ipatterns)
>>> ignorethis = igf(ddftopdir,os.listdir(ddftopdir))

Traceback (most recent call last):
  File "<pyshell#60>", line 1, in <module>
    ignorethis = igf(ddftopdir,os.listdir(ddftopdir))
  File "C:\Python27\lib\shutil.py", line 138, in _ignore_patterns
    ignored_names.extend(fnmatch.filter(names, pattern))
  File "C:\Python27\lib\fnmatch.py", line 49, in filter
    pat=os.path.normcase(pat)
  File "C:\Python27\lib\ntpath.py", line 46, in normcase
    return s.replace("/", "\\").lower()
AttributeError: 'tuple' object has no attribute 'replace'

>>> igg = shutil.ignore_patterns('*.txt', '*.hdf', '*.pdf', '*.png')
>>> ignorethat = igg(ddftopdir, os.listdir(ddftopdir))
>>> ignorethat
set(['Chi2.png', 'DTSdata.hdf', 'TST.hdf', 'BullNoseDiffs.png', 
'DTSall.hdf', 'Symmetry.pdf'])
>>>
++++++++++++++++++++++++++++
Why does it fail on passing in a tuple of ignore strings? I thought the , 
(comma) is pretty much the tuple constructor (if that is the right word).

How can I solve this? Is there a way to convert a tuple of strings in a form 
that will be accepted?

Thank you in advance,
Alex van der Spek





More information about the Python-list mailing list