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


Groups > comp.lang.python > #25632 > unrolled thread

shutil ignore fails on passing a tuple?

Started by"Alex van der Spek" <zdoor@xs4all.nl>
First post2012-07-19 18:43 +0200
Last post2012-07-19 15:20 -0400
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  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

#25632 — shutil ignore fails on passing a tuple?

From"Alex van der Spek" <zdoor@xs4all.nl>
Date2012-07-19 18:43 +0200
Subjectshutil ignore fails on passing a tuple?
Message-ID<50083935$0$6851$e4fe514c@news2.news.xs4all.nl>
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

[toc] | [next] | [standalone]


#25633

From"Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Date2012-07-19 16:52 +0000
Message-ID<mailman.2306.1342716795.4697.python-list@python.org>
In reply to#25632
> >>> 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.  

[toc] | [prev] | [next] | [standalone]


#25634

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2012-07-19 12:55 -0400
Message-ID<mailman.2307.1342716919.4697.python-list@python.org>
In reply to#25632
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

[toc] | [prev] | [next] | [standalone]


#25645

FromDave Angel <d@davea.name>
Date2012-07-19 15:20 -0400
Message-ID<mailman.2314.1342725661.4697.python-list@python.org>
In reply to#25632
On 07/19/2012 12:43 PM, Alex van der Spek wrote:
> This beats me:
> ++++++++++++++++++++
>>>> ipatterns
> ('*.txt', '*.hdf', '*.pdf', '*.png')
>>>> igf = shutil.ignore_patterns(ipatterns)
>>>> ignorethis = igf(ddftopdir,os.listdir(ddftopdir))
>
> <SNIP>
> 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).
>

ignore_patterns() is not looking for a tuple, it's looking for one or
more strings, as separate arguments.  If you already have the tuple, you
can expand it by using the asterisk, as Prasad ha pointed out.

igf = shutil.ignore_patterns(*ipatterns)

-- 

DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web