def organize ( cvsfile, write_func, *args ):
    argv = args[0]
    if len(argv) < 2:
        sys.stderr.write("Need two extra arguments for 'organize', e.g. command: <1,2,3> <4,5,6> means the first 1,2,3 will be used as dependent variables/response, and 4,5,6 will be used as independent variables/terms/predictors.\n")
        sys.exit()

    responses_num = map(int,argv[0].split(","))
    predictors_num = map(int,argv[1].split(","))
    
    fields = cvsfile.fieldnames
    responses_label = map(lambda x:"res."+fields[x],responses_num)
    predictors_label = map(lambda x:"pre."+fields[x],predictors_num)

    responses_name = map(lambda x:fields[x],responses_num)
    predictors_name = map(lambda x:fields[x],predictors_num)
    
    #write_func( "#%s\t%s\n" \
    #            % ( ",".join(map( lambda x:str(x[0])+":"+str(x[1]) , zip(responses_num,responses_name) )),
    #                ",".join(map( lambda x:str(x[0])+":"+str(x[1]) , zip(predictors_num,predictors_name) ))) )
    write_func( "%s\t%s\n" \
                % ( ",".join(map( lambda x:str(x) , responses_name )),
                    ",".join(map( lambda x:str(x) , predictors_name ))) )

    for l in cvsfile:
        # for responses
        t_str_list = []
        for t in responses_name:
            t_str_list.append(l.setdefault(t,"NA"))
        # for predictors
        v_str_list = []
        for v in predictors_name:
            v_str_list.append(l.setdefault(v,"NA"))

        write_func( "\t".join( (",".join(t_str_list),",".join(v_str_list)) ) )
        write_func( "\n" )
Test service.list
dataset/ETHPy150Open taoliu/taolib/Scripts/ce_histone_matrix.py/organize--crossover with--dataset/ETHPy150Open saltstack/salt/tests/integration/modules/mac_service.py/MacServiceModuleTest.test_list