I try to run the following code in the compiler. But it doesn't give any result. Can anyone know how should I modify it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I try to run the following code in the compiler. But it doesn't give any result. Can anyone know how should I modify it?

coding error https://code.sololearn.com/c5x02sqQy2rW/?ref=app

6th Sep 2018, 12:06 PM
Saeed Mozaffari
Saeed Mozaffari - avatar
15 Answers
+ 7
Saeed Mozaffari Convert your regex pattern to a raw string as r'len(daught)er)'. Also, you should close the file to avoid leaks using `fh.close()` on line 10.
6th Sep 2018, 2:16 PM
Eduardo Petry
Eduardo Petry - avatar
+ 2
try your code on pc because there is no Emma.txt file in your android if it is exist in your device then you can't call here because you can only import such these directories only on pc not android.
6th Sep 2018, 4:18 PM
Maninder $ingh
Maninder $ingh - avatar
+ 2
Saeed Mozaffari try this code hope it will help you. but try on computer not android and file should be exist in your computer Emma.txt https://code.sololearn.com/cWFv8dcb3fHG/?ref=app
6th Sep 2018, 4:39 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
Maninder Singh Thank you so much.
6th Sep 2018, 4:43 PM
Saeed Mozaffari
Saeed Mozaffari - avatar
+ 1
Saeed Mozaffari i have bug in my code please change the f.read() into f.readlines() because we need to check line by line. I think you are doing re module it can be made more simple for more explanation watch this video. https://youtu.be/K8L6KVGG-7o
6th Sep 2018, 4:58 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
Maninder Singh Yes, I'm working on re module. Thank you.
6th Sep 2018, 5:02 PM
Saeed Mozaffari
Saeed Mozaffari - avatar
+ 1
Emerson Prado Yes, in SoloLearn and i watched a tutorial video about regular expression in my own language.
7th Sep 2018, 10:38 AM
Saeed Mozaffari
Saeed Mozaffari - avatar
0
Where is file "Emma.txt"?
6th Sep 2018, 12:16 PM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado Where above code there is. In a folder named 'regular expression'. i save that file in a nodepad in my pc.
6th Sep 2018, 12:21 PM
Saeed Mozaffari
Saeed Mozaffari - avatar
0
Saeed Mozaffari OK. Which are the file contents?
6th Sep 2018, 12:25 PM
Emerson Prado
Emerson Prado - avatar
0
Maninder Singh On my pc it gives no output.
6th Sep 2018, 4:26 PM
Saeed Mozaffari
Saeed Mozaffari - avatar
6th Sep 2018, 4:27 PM
Saeed Mozaffari
Saeed Mozaffari - avatar
0
Saeed Mozaffari If your file only contains 'Emma' and you're trying to match for 'len(daught)er', it simply doesn't match, so you won't get any output. Populate your file with content that can match. Did you study the RegEx classes?
6th Sep 2018, 5:47 PM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado Excuse me, in regular expression re.search find and show an specific character from the file????
11th Sep 2018, 2:05 PM
Saeed Mozaffari
Saeed Mozaffari - avatar
0
Saeed Mozaffari Not a specific character, but the string that matched the expression. For an example, 'len(daught)er' would match 'lendaughtet' and return 'daught'.
11th Sep 2018, 2:08 PM
Emerson Prado
Emerson Prado - avatar