shutil ignore fails on passing a tuple?

Joel Goldstick joel.goldstick at gmail.com
Thu Jul 19 18:55:17 CEST 2012


On Thu, Jul 19, 2012 at 12:43 PM, Alex van der Spek <zdoor at xs4all.nl> wrote:
> 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'

What is s?  It needs to be a string.  If s is a tuple with string
values, you will have to iterate over each to replace.  Or I believe
you could use map.
>
>>>> 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
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick



More information about the Python-list mailing list