cta-observatory/dragonboard_testbench

Update of offset_cell_sample.py

Opened this issue · 7 comments

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?

i have no opinion here

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?

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?

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

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 ...

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?

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.