Sep-07-2019, 10:17 PM
In the following code I open two files (one to read from and the other to write to). I want to read through f until I get to a left brace ("{") before I start writing out to g. The left brace is there, but the code never executes the first break. The output of print(x) looks like this on the console:
b'='
b' '
b'{'
b'\r'
b'\n'
b'\t'
b'0'
You can see the brace in the third line. I've tried a number of formats for the right side of the == in the if str(x) == '{': line, but I still can't get it to break. What am I doing wrong? Thanks.
b'='
b' '
b'{'
b'\r'
b'\n'
b'\t'
b'0'
You can see the brace in the third line. I've tried a number of formats for the right side of the == in the if str(x) == '{': line, but I still can't get it to break. What am I doing wrong? Thanks.
with open("E:\\Karl\\Documents\\Sculpture\\Prime Time\\Digits\\1d_inv_conv.c", 'w') as g: with open("E:\\Karl\\Documents\\Sculpture\\Prime Time\\Digits\\1d_inv.c", 'rb') as f: while True: x = f.read(1) print(x) if str(x) == '{': break j = 1 while (j == 1): for i in range(5): x = f.read(1) if x == '': j = 0 break # print(x) g.write(str(x)) g.write(", ") g.write("\n")