简体   繁体   中英

Change parameter value with iteration

I have an Excel file, and I need to grab some data from it. When I use regular integers, everything works just fine, but now I got very stuck - how can I change row value? That's what I have for now

dict_keys = ['Id', 'First name', 'Age', 'Condition Name', 'BiRad', 'Relevant Modality']
dict_values = [p_id, person_name, p_age, name, br, r]
if f == 'Mass':   
    #concatvals accepts (row, col, width, start, stop)
    shape = concatvals(row, 14, 5, 14, 19) #if row = 0
    margin = concatvals(row, 14, 5, 14, 19) #here row should be 1
    density = concatvals(row, 14, 5, 14, 19) # and here 2 - how to achieve that?
    dict_keys += ['Relevant Finding','Shape', 'Margin', 'Density']
    dict_values += [f, shape, margin, density]

And that's what I tried:

if f == 'Mass':
    params = [shape, margin, density]
    loc = (row, 14, 5, 14, 19)
    for param in params:
        params[i] = concatvals(loc)
        loc[0] +=1

But didn't succeed to go further. Any suggestions? Thanks!

Make row a loop parameter, and save the calculated values in an array:

dict_keys = ['Id', 'First name', 'Age', 'Condition Name', 'BiRad', 'Relevant Modality']
dict_values = [p_id, person_name, p_age, name, br, r]

#concatvals accepts (row, col, width, start, stop)
vals = []
for row in range(3):
    vals += concatvals(row, 14, 5, 14, 19)
dict_keys += ['Relevant Finding','Shape', 'Margin', 'Density']
dict_values += [f]
dict_values += vals

Its a bit confusion you use dict__ for things which are not a dict, but a list... If I understand what you want I would arrive at this:

params = {'Mass': ['shape', 'margin', 'density'],
          'Next': ['some', 'other', 'list']}
if f == 'Mass':
    loc = (row, 14, 5, 14, 19)
    result = [f]
    for param in params[f]:
        result.append(concatvals(loc))
        loc[0] +=1
    dict_keys += ['Relevant Finding','Shape', 'Margin', 'Density']
    dict_values += result
elif f == 'Next':
    ... etc ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM