Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25633

RE: shutil ignore fails on passing a tuple?

From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Subject RE: shutil ignore fails on passing a tuple?
Date 2012-07-19 16:52 +0000
References <50083935$0$6851$e4fe514c@news2.news.xs4all.nl>
Newsgroups comp.lang.python
Message-ID <mailman.2306.1342716795.4697.python-list@python.org> (permalink)

Show all headers | View raw


> >>> 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?
>

Untested, but I think it should work.
igf = shutil.ignore_patterns(*ipatterns)

Ramit

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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