shutil ignore fails on passing a tuple?

A

Alex van der Spek

This beats me:
++++++++++++++++++++
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'
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
 
P

Prasad, Ramit

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

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'

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.
 
J

Joel Goldstick

This beats me:
++++++++++++++++++++

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


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.
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
 
D

Dave Angel

This beats me:
++++++++++++++++++++

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top