Example #1
0
def check_get_value():
    with open('result.txt', 'w') as f:
        f.write('name,X0,X1,X2,X3,X4,X5\n')
        f.write('val,0.125,1.1,2.3,3.5,4.7,5.99\n')
    ott.assert_almost_equal(coupling_tools.get_value('result.txt', skip_line=1, skip_col=3,col_sep=','), 2.3)
    ott.assert_almost_equal(coupling_tools.get_value('result.txt', skip_line=1, skip_col=-1,col_sep=','), 5.99)
    os.remove('result.txt')
# * `skip_tokens` is a list of N items (number of tokens to ignore before reading the value),
# * `skip_lines` is a list of N items (number of rows to ignore before reading the value),
# * `skip_cols` is a list of N items (number of columns to ignore before reading the value),
# * `Y` is a list of N floats.
#
# And to get a single value:
#
# `Y = get_value(filename, token=None, skip_token=0, skip_line=0, skip_col=0)`

# %%
# Consider for example the following file.

# %%
content = '''
1 2 3 04 5 6
7 8 9 10
11 12 13 14
'''

# %%
f = open("results.txt", "w")
f.write(content)
f.close()

# %%
# We want to read the number `9`.

# %%
Y = ct.get_value("results.txt", skip_line=1, skip_col=2)
Y