Hello, I want to read the below matrix, identify when the characters in front of "want = " are equal to "1" and then save in an array and in an output file the characters above. But I don't know how to identify the second line and store in a variable:
alpha=0 beta=2 gamma=50 want = 0 alpha=0 beta=2 gamma=50 want = 1 alpha=0 beta=2 gamma=50 want = 0 alpha=0 beta=2 gamma=50 want = 1 alpha=0 beta=2 gamma=50 want = 0 This is part of the code: try: datadir = '/home/me/Test_python/' fileHandle = open( "%s/teste.txt"%datadir, 'r' ) vector = [ ] for line in fileHandle.readlines(): line=line.strip() a = line.split(" ")[0] print a b = line.split(" ")[1] print b c = line.split(" ")[2] print c d = line.split(" ")[3] print d if d == "1": vector.append([a,b,c]) n = n + 1 fileHandle.close() file = open("saida.txt","w") for cont in range(n): file.write = vector except: print "Exception" sys.exit( 1 ) When I execute the code there is an error when the loop finds the second line [felipe@grumari Test_python]$ python verificar.py alpha=0 beta=2 gamma=50 Exception Thanks, Felipe
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor