accessing parameters in different areas

A forum for general discussion of the Python programming language.

accessing parameters in different areas

Postby johann99 » Wed Aug 21, 2013 4:02 pm

There’s one thing that I’m trzing to figure out that would make my code much easier.
So I’m defining my compute_field-function that produce the information “info_for_click”
Then I’m calling the compute_field-function in my decision-function that is inside my main-function. Here the actual data for info_for_click gets computed. Then in the click_row-function (inside main) I would need access to the data info_for_click that was produced inside the compute_field-function inside my decision-function.
How do I do that? Thanks a lot in advance.

Code: Select all
def compute_field(s, A, phi,  k, Vebit, Vebitmax, cavmaxreal, factor, betaS, minimumf, maximumf, diffE, E):
    …
    if condition_field:
        Qout.append(k)
        fieldout.append(fieldreal)
        numberout.append(s)
        Energyout.append(E)
        set_cells(table, len(Qout) - 1, k, Vebit, s, E)
    # no provide information for click
    info_for_click = zip(Qout, fieldout, numberout, Energyout)
    return info_for_click

def main():
    Qcont, A1, Around, nameiso, abu, qdivbya, abu2, information = readcontaminationfile()
    cavmaxCSS, cavmaxreal, factor = readcavmaxfile()
    phi, Qin, A, E, diffE, minimumf, maximumf, Vebitmax, check2, check1, check3, check4, checks,\
           number, numbers, diffqa0, cavlist, combo = getInputs(A1, Around, nameiso, Qcont, factor)
    alarm(cavlist, cavmaxCSS, number)
    info_for_click = decision(phi, Qin, A, E, diffE, minimumf, maximumf, Vebitmax, checks, \
             number, numbers, cavlist, factor, cavmaxCSS, cavmaxreal)
    clickrow(Qcont, A1, nameiso, qdivbya, abu2, information, A, diffqa0, check3, check4, factor, \
             phi, minimumf, maximumf, cavmaxreal, combo)


def decision(phi, Qin, A, E, diffE, minimumf, maximumf, Vebitmax, checks, \
             number, numbers, cavlist, factor, cavmaxCSS, cavmaxreal):
    Q = range(1 , Qin + 1, 1)
    for i in Q:
        Vebit = 12*A/i   
# Ist possibility: fixed number, compute Energy
        if checks == [1, 0, 0, 1]:
            compute_energy(number, A, phi,  i, cavlist, Vebit, Vebitmax, cavmaxCSS, factor, betaS)
        elif checks == [1, 0, 1, 0]:
            compute_field(number, A, phi,  i, Vebit, Vebitmax, cavmaxreal, factor, betaS, minimumf, maximumf, diffE, E)
        elif checks == [0, 1, 1, 0]:
        # for some reason: after checks no for..
            normann = 3
            for j in numbers:
                compute_field(j, A, phi,  i, Vebit, Vebitmax, cavmaxreal, factor, betaS, minimumf, maximumf, diffE, E)
               
                else:
            refresh()
def clickrow(Qcont, A1, nameiso, qdivbya, abu2, information, A, diffqa0, check3, check4, factor, \
             phi, minimumf, maximumf, cavmaxreal, combo):
               
    Qchosen = float(text1[0])
    Number = float(text1[2])
    Energy = float(text1[3])

               
    if check4 == 0 and check3 == 1:
        listfields = int(Number)*[fieldreal]
        for Qchosen, fieldreal, Number, Energy in info_for_click:
     ...                        ...
if __name__ == '__main__': main()



Thanks a lot in advance!!
Best, Johann
johann99
 
Posts: 6
Joined: Fri Aug 16, 2013 2:05 am

Re: accessing parameters in different areas

Postby metulburr » Wed Aug 21, 2013 5:13 pm

stuff like this is the most rediculous thing i have ever seen
Code: Select all
    phi, Qin, A, E, diffE, minimumf, maximumf, Vebitmax, check2, check1, check3, check4, checks,\
           number, numbers, diffqa0, cavlist, combo = getInputs(A1, Around, nameiso, Qcont, factor)

or this:
Code: Select all
Qcont, A1, Around, nameiso, abu, qdivbya, abu2, information = readcontaminationfile()

or this:
Code: Select all
def compute_field(s, A, phi,  k, Vebit, Vebitmax, cavmaxreal, factor, betaS, minimumf, maximumf, diffE, E):

you get the point.

with that many arguments it makes the code 10 times harder to read, more error prone, and just defies python's simplicity. A class' object would consume up all the arguments in these functions, making way easier to read, maintain, and understand (especially when asking for help). It actually looks like someone wrote this code to make it harder to read. But at the same time, the writer also has to understand it a year from now.

Then in the click_row-function (inside main) I would need access to the data info_for_click that was produced inside the compute_field-function inside my decision-function. How do I do that?

a class is your answer
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: accessing parameters in different areas

Postby johann99 » Wed Aug 21, 2013 5:47 pm

I am just starting up with coding. Could you please give me an example how to define a class in this specific context
johann99
 
Posts: 6
Joined: Fri Aug 16, 2013 2:05 am


Return to General Discussions

Who is online

Users browsing this forum: Google [Bot] and 2 guests