# Julia Python equivalent of \_\_main\_\_?

**URL:** <https://discourse.julialang.org/t/julia-python-equivalent-of-main/35433>\
**Category:** New to Julia\
**Created:** [March 2, 2020, 10:50pm UTC](https://discourse.julialang.org/t/julia-python-equivalent-of-main/35433 "2020-03-02T22:50:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darione](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darione/32/12160_2.png) [@Darione](https://discourse.julialang.org/u/Darione)\
**Post date:** [March 2, 2020, 10:50pm UTC](https://discourse.julialang.org/t/julia-python-equivalent-of-main/35433/1 "2020-03-02T22:50:42Z")

</div>

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

```julia
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?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [March 2, 2020, 10:53pm UTC](https://discourse.julialang.org/t/julia-python-equivalent-of-main/35433/2 "2020-03-02T22:53:25Z")

</div>

See [Frequently Asked Questions · The Julia Language](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:

```julia
function main()
   # do stuff
end

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

```

---

<div class="post-metadata">

**Author:** ![Darione](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darione/32/12160_2.png) [@Darione](https://discourse.julialang.org/u/Darione)\
**Post date:** [March 3, 2020, 10:05am UTC](https://discourse.julialang.org/t/julia-python-equivalent-of-main/35433/3 "2020-03-03T10:05:38Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![jsbryan4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsbryan4/32/34173_2.png) [@jsbryan4](https://discourse.julialang.org/u/jsbryan4)\
**Post date:** [June 17, 2022, 6:24pm UTC](https://discourse.julialang.org/t/julia-python-equivalent-of-main/35433/4 "2022-06-17T18:24:28Z")

</div>

This solution does not work when using vscode. When I print `abspath(PROGRAM_FILE)` and `@ __FILE__ ` I get

```julia
/Users/user/.vscode/extensions/julialang.language-julia-1.6.17/scripts/terminalserver/terminalserver.jl

/Users/user/pathtofile/main.jl

```

Is there a way for this to work in vscode?

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 17, 2022, 6:50pm UTC](https://discourse.julialang.org/t/julia-python-equivalent-of-main/35433/5 "2022-06-17T18:50:36Z")

</div>

This solution was meant to run the script only if it was called directly and do nothing otherwise. VSCode does not call the script directly, so it does nothing, as it should. Why do you need the `if`? Can’t you just:

```julia
function main()
   # do stuff
end

main()

```
