Julia Python equivalent of __main__?

In Julia, what is the python equivalent of if name == “main” ?
For example:

def main():
    pass

def print_tre_volte(parola):
    print(parola)
    print(parola)
    print(parola)

if __name__ == "__main__":
    main()

It the script is run directly, it will does main(), otherwise no.

In Julia?

1 Like

See https://docs.julialang.org/en/v1/manual/faq/#How-do-I-check-if-the-current-file-is-being-run-as-the-main-script?-1. Something like the following should work:

function main()
   # do stuff
end

if abspath(PROGRAM_FILE) == @__FILE__
    main()
end
15 Likes

It works, thanks!

I know (emh, from yesterday… ) that in julia there is not the script-mentality as in python, but, you know, for a beginner, this is very simple to use …

1 Like