Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > shutil ignore fails on passing a tuple?

Reply
Thread Tools

shutil ignore fails on passing a tuple?

 
 
Alex van der Spek
Guest
Posts: n/a
 
      07-19-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


 
Reply With Quote
 
 
 
 
Prasad, Ramit
Guest
Posts: n/a
 
      07-19-2012
> >>> ipatterns

> ('*.txt', '*.hdf', '*.pdf', '*.png')

> >>> igf = shutil.ignore_patterns(ipatterns)
> >>> ignorethis = igf(ddftopdir,os.listdir(ddftopdir))

>
> Traceback (most recentcall 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 isconfidential 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.
 
Reply With Quote
 
 
 
 
Joel Goldstick
Guest
Posts: n/a
 
      07-19-2012
On Thu, Jul 19, 2012 at 12:43 PM, Alex van der Spek <(E-Mail Removed)> 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
 
Reply With Quote
 
Dave Angel
Guest
Posts: n/a
 
      07-19-2012
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is the shutil module called shutil? Fletcher Johnson Python 11 09-26-2011 04:18 AM
Ignore + TEST + Ignore SpooderStank Computer Support 2 04-08-2004 11:26 AM
Searching for Exact Phrase - should I ignore the ignore words? Rob Meade ASP General 6 03-01-2004 11:28 AM
file copy shutil Joe Python 1 02-09-2004 07:02 PM
shutil.move() Error ([Errno 17] File exists:) on win32 bmgz Python 1 12-16-2003 08:41 PM



Advertisments