Python Forum
unable to print the list when using re.findall()
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unable to print the list when using re.findall()
#1
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
#2
You have been advised to use proper tags! Please, repost with code tags! And add the full Traceback in error tags.
#3
# -*- 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
#4
(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.
#5
okay I would follow the same in future. pls answer the above
#6
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.


Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to remove all elements from list based on a condition sg_python 3 377 Jan-27-2024, 04:03 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 427 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  regex findall() returning weird result Radical 1 588 Oct-15-2023, 08:47 PM
Last Post: snippsat
  How do you get Python to print just one value in a list? 357mag 3 967 May-17-2023, 09:52 PM
Last Post: rob101
  Python: re.findall to find multiple instances don't work but search worked Secret 1 1,173 Aug-30-2022, 08:40 PM
Last Post: deanhystad
  Print List to Terminal DaveG 2 1,408 Apr-02-2022, 11:25 AM
Last Post: perfringo
  Unable to use random.choice(list) in async method spacedog 4 3,354 Apr-29-2021, 04:08 PM
Last Post: spacedog
  Print max numbers in a list jimmoriarty 1 2,118 Sep-25-2020, 07:29 AM
Last Post: DPaul
  regex.findall that won't match anything xiaobai97 1 1,972 Sep-24-2020, 02:02 PM
Last Post: DeaD_EyE
  Unable to print stuff from while loop Nick1507 4 2,280 Sep-17-2020, 02:26 PM
Last Post: Nick1507

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020