I'm attempting to write my first python program; translating a program I wrote in C++ last week. I have a question about re.match. I'm very new to regular expressions; as I have just switched to C++/Python on Fedora from Java on Windows. Anyhoo, here is my problematic function:
def ReadFile(): status = 0 report = open('/home/joshua/Cactus/simfactory/bin/Testbuild.txt', 'r') fail = re.search('(\bCommand\B)/>(\breturned\B)/>(\bexit\B)/>(\bstatus\B)/>',report) if fail: status = 2 report.close() else: status == 1 report.close()
There's a little more to it than that, but this is where the problem is. When I try to run, I get this error:
File "/home/joshua/eclipse/workspace/PyShellTest/src/ShellTest.py", line 22, in ReadFile fail = re.search('(\bCommand\B)/>(\breturned\B)/>(\bexit\B)/>(\bstatus\B)/>',report) File "/usr/lib64/python2.7/re.py", line 142, in search return _compile(pattern, flags).search(string) TypeError: expected string or buffer
I realize I'm probably doing something really elementary wrong, but my overall unfamiliarity with regular expressions is hurting me. Any push in the right direction would be greatly appreciated. Thanks in advance.
ETA: I have no idea why the ending \b's are capitalized. They are lowercase in the code and just switched on the board for some reason.
This post has been edited by jhar131: 10 June 2011 - 01:28 PM