Example:
filetype = 'rtf'
files = ['doc.txt', 'stuff.rtf', 'artfunction.exe', 'rtfunc.bat', 'doc2.rtf']
print('\n'.join(filename for filename in files if filename.endswith('.'+filetype)))
BTW iteritems is being deprecated, use items method instead.
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
You have not proper file list:
>>> file_list = urllib.urlretrieve("http://www.tvn.com.au/tvnlive/v1/system/modules/org.tvn.website/resources/sectionaltimes/")
>>> print(file_list)
('c:\\docume~1\\veijal~1.yks\\locals~1\\temp\\tmpq6ol5c', <httplib.HTTPMessage instance at 0x00ED12B0>)
>>> help(urllib.urlretrieve)
Help on function urlretrieve in module urllib:
urlretrieve(url, filename=None, reporthook=None, data=None)
>>> print(list(file_list[1]))
['content-length', 'set-cookie', 'expires', 'server', 'connection', 'date', 'content-type']
>>> print(open(file_list[0]).read())
<html>
<title>tvn.com.au</title>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><img src="/tvnlive/v1/system/modules/org.tvn.website/resources/graphics/g_404_error.gif">
<font color="#919191"; size="1"; face="Verdana">The page you requested is not available. Please click <a href="/tvnlive/v1/system/modules/org.tvn.website/jsptemplates/tvn_main_menu.jsp;jsessionid=53391838F909BEE13C315632CE7E2BC1.tvnEngine2?TVNSESSION=53391838F909BEE13C315632CE7E2BC1.tvnEngine2" style="color: red; text-decoration: none; image-decoration: none; font-weight: bolder;">here</a> to return to the homepage.</font>
</td>
</tr>
</table>
</body>
</html>
>>>
Print the values to check what you have.
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852