Python Forum
unable to print the list when using re.findall() - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: unable to print the list when using re.findall() (/thread-5295.html)



unable to print the list when using re.findall() - satyaneel - Sep-27-2017

code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 20 07:44:11 2017

@author: Srinu
"""
import re
f=open('D:\EDUCATION\python\google-python-exercises\\babynames\\baby2008.html','r')
tuples=re.findall(r'<td>(\d+)</td><td>(\w+)</td><td>(\w+)</td>','f.read()')
print(tuples)

error:

runfile('D:/EDUCATION/python/my progs/strs.py', wdir='D:/EDUCATION/python/my progs')
[]

printing empty list as above


RE: unable to print the list when using re.findall() - buran - Sep-27-2017

You have been advised to use proper tags! Please, repost with code tags! And add the full Traceback in error tags.


RE: unable to print the list when using re.findall() - satyaneel - Sep-27-2017

# -*- coding: utf-8 -*-
"""
Created on Wed Sep 20 07:44:11 2017

@author: Srinu
"""
import re
#opening the file in read mode
f=open('D:\EDUCATION\python\google-python-exercises\\babynames\\baby2008.html','r')
#Trying to extract the details like rank,firstname,lastname from the file
tuples=re.findall(r'<td>(\d+)</td><td>(\w+)</td><td>(\w+)</td>','f.read()')
#printing the extracted lists [rank,firstname,lastname]
print(tuples)

error:
runfile('D:/EDUCATION/python/my progs/strs.py', wdir='D:/EDUCATION/python/my progs')

list is not printing


RE: unable to print the list when using re.findall() - buran - Sep-27-2017

(Sep-27-2017, 09:58 AM)buran Wrote: You have been advised to use proper tags! Please, repost with code tags! And add the full Traceback in error tags.

I think the above is pretty clear. Please, follow the forum rules unless you want ban.


RE: unable to print the list when using re.findall() - satyaneel - Sep-27-2017

okay I would follow the same in future. pls answer the above


RE: unable to print the list when using re.findall() - buran - Sep-27-2017

Any particular reason not to follow rules NOW? Obviously you don't care about following rules, so I will now lock this thread. Please, repost in a new thread and following rules.