Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMUZ140330 Simbarashe Chibgwe
2,825 PointsImport re. Create an re.match() for the word "Four" in the data variable. Assign this to a new variable named first.
error says
first doesnt seem to be a regex blabla. Cant really figure wher i am missing it
import re
file_object = open("basics.txt", encoding="utf-8")
data = file_object.read()
file_object.close()
first = r'Four'
print(re.match(first, data))
2 Answers
William Li
Courses Plus Student 26,868 PointsHi, Simbarashe Chibgwe you should assign the re.match
result to variable first, then print it.
first = re.match(r'Four', data)
print(first)
Daniel Akalu
5,018 Pointsfile_object = open("basics.txt") data = file_object.read() file_object.close() import re first = re.match(r'Four', data)
MUZ140330 Simbarashe Chibgwe
2,825 PointsMUZ140330 Simbarashe Chibgwe
2,825 PointsThank you so much, it worked. But for the sake of learning, can u point out what is wrong with my first code?? I guess that way should have worked as well, but it did not.
Any suggestions
William Li
Courses Plus Student 26,868 PointsWilliam Li
Courses Plus Student 26,868 PointsSure, but first I must say that I got a little carried away by your code and didn't read the challenge description of Part 3 very carefully.
There's really no need for the print statement at the second line.
first = re.match(r'Four', data)
Is all the Challenge is asking for.
So now back to your question. Obviously the grader for this part is checking whether your variable first is holding the correct value; therefore,
You should be able to see that these two first variable don't hold the same value, right? Hope that helps.
MUZ140330 Simbarashe Chibgwe
2,825 PointsMUZ140330 Simbarashe Chibgwe
2,825 PointsLook at myself, hahaha thanks again. You just uncovered the whole secret here.
I appreciate, and now i can use the trick with confidence