I'm new to python and need help with a problem. Basically I need to open a file and read it which I can do no problem. The problem arises at line 0, where I need to check the header format.
The header needs to be in the format: p wncf nvar nclauses hard
where 'nvar' 'nclauses' and 'hard' are all positive integers.
For example:
p wncf 1563 817439 186191
would be a valid header line.
Here is coding i have already thanks to a question people answered earlier:
import re
filename = raw_input('Please enter the name of the WNCF file: ')
f = open(filename, 'r')
for line in f:
p = re.compile('p wncf \d+ \d+ \d+$')
if p.match(line[0]) == None:
print "incorrect format"
I still get an incorrect format even when the file is of a correct format. Also, would it be possible to assign the integers to an object?
Thanks in advance.