Python Forum
Data written in loop not available afterwards
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Data written in loop not available afterwards
#1
Greetings folks,

I am still fairly new to python and have a small problem with a function I have written:

    def evaluate_tests(test_results):
        evaluation = {};
        n = 0;
        for tests in test_results:
            test_eval = {};
            test_eval['error'] = [];
            test_eval['incomplete_nodes'] = [];
            test_eval['finished_fbc'] = 0;
            test_eval['finished_mfcn'] = 0;
            sum_fbc_error = 0;
            sum_mfcn_error = 0;
            sum_fbc_in = 0;
            sum_mfcn_in = 0;
            for test_result in tests:
                fbc = test_result['find_best_coverage'];
                mfcn = test_result['max_fully_covered_nodes'];
                print("fbc['incomplete_nodes']");
                print(fbc['incomplete_nodes']);
                print("mfcn['incomplete_nodes']");
                print(mfcn['incomplete_nodes']);
                print("mfcn fbc incomplete notes difference");
                print(abs(len(fbc['incomplete_nodes']) - len(mfcn['incomplete_nodes'])));
                test_eval['error'].append(abs(fbc['errors'] - mfcn['errors']));
                test_eval['incomplete_nodes'].append(abs(len(fbc['incomplete_nodes']) - len(mfcn['incomplete_nodes'])));
                test_eval['finished_fbc'] += 1;
                test_eval['finished_mfcn'] += 1;
                sum_fbc_error += fbc['errors'];
                sum_mfcn_error += mfcn['errors'];
                sum_fbc_in += len(fbc['incomplete_nodes']);
                sum_mfcn_in += len(mfcn['incomplete_nodes']);
                print("error difference fbc mfcn");
                print(test_eval['error']);
                print("test_eval['incomplete_nodes']");
                print(test_eval['incomplete_nodes']);
All initiated variables of the dictionary

test_eval['error'] = [];
test_eval['incomplete_nodes'] = [];
test_eval['finished_fbc'] = 0;
test_eval['finished_mfcn'] = 0;
will be filled with data inside the loop (the print command shows that to me) but are empty outside (or 0) of the loop (as they were initialised), since I initialised them before the loop I actually expected to be available also after the loop finished - can somebody tell me how to fix it (and what I did wrong)?

Thank you very much in advance!
Reply


Messages In This Thread
Data written in loop not available afterwards - by Weird - Mar-28-2020, 03:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I have written a program that outputs data based on GPS signal kalle 1 1,222 Jul-22-2022, 12:10 AM
Last Post: mcmxl22
  2 or more data to be written in a row plumberpy 2 1,548 Nov-25-2021, 07:44 AM
Last Post: Gribouillis
  Formatting file data written to file. melblanc 2 2,310 Jan-15-2020, 03:27 PM
Last Post: melblanc
  csv data not written into avro file rajeshdatla2000 2 3,072 Aug-12-2017, 01:38 PM
Last Post: Bass

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020