Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25634
| References | <50083935$0$6851$e4fe514c@news2.news.xs4all.nl> |
|---|---|
| Date | 2012-07-19 12:55 -0400 |
| Subject | Re: shutil ignore fails on passing a tuple? |
| From | Joel Goldstick <joel.goldstick@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2307.1342716919.4697.python-list@python.org> (permalink) |
On Thu, Jul 19, 2012 at 12:43 PM, Alex van der Spek <zdoor@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
shutil ignore fails on passing a tuple? "Alex van der Spek" <zdoor@xs4all.nl> - 2012-07-19 18:43 +0200 RE: shutil ignore fails on passing a tuple? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-07-19 16:52 +0000 Re: shutil ignore fails on passing a tuple? Joel Goldstick <joel.goldstick@gmail.com> - 2012-07-19 12:55 -0400 Re: shutil ignore fails on passing a tuple? Dave Angel <d@davea.name> - 2012-07-19 15:20 -0400
csiph-web