cta-observatory / dragonboard_testbench

Collection of programs to look at test data from the LST prototype camera.
1 stars 2 forks source link

Update of offset_cell_sample.py #45

Open MHoerbe opened 8 years ago

MHoerbe commented 8 years ago

It is nice to have a script that calculates sample_id-dependent offsets. However, many things are hard-coded and docopt handling is missing.

Should this file be updated to make its usage become more like fit_delta_t.py?

dneise commented 8 years ago

i have no opinion here

MHoerbe commented 8 years ago

all right. could you explain how that script is used? it only contains a function "func(chunk, name)" and no main. is it used by another script or is it autonomous?

dneise commented 8 years ago

You say "it contains no main". I guess you mean, it does not contain a line like this:

if __name__ == "__main__":
    # do stuff

Do I understand this correctly?

MHoerbe commented 8 years ago

exactly. probably there are more possibilities? would like to understand this entirely

dneise commented 8 years ago

I would like to enable you to answer this question yourself. Instead of just giving you this answer. So please create two test files, and compare what happens, when you call them like this:

$ python <scriptname>.py

First create a file named no_main.py

# no_main.py

def a_function(foo):
    print("somebody called a_function")
    print("foo is {}".format(foo))

print("I am no_main.py")
print("Somebody is calling the print function ")
a_function(foo="bar")

Second create a file called with_main.py:

# with_main.py

def a_function(foo):
    print("somebody called a_function")
    print("foo is {}".format(foo))

if __name__ == "__main__":
    print("I am with_main.py")
    print("Somebody is calling the print function ")
    a_function(foo="bar")

call both of these files ... and see what happens ...

maxnoe commented 8 years ago

an now create a second script in the same folder and use:

from no_main import a_function

and

from with_main import a_function

What's the difference if you run the script?

MHoerbe commented 8 years ago

Nice, think I got it. Just for the record, with and without main, both scripts do the same, whereas only the no_main executes the function upon import. However, one can call the function in both cases. Nice to know and thanks for your advice.