# "Import guard" in julia

**URL:** https://discourse.julialang.org/t/import-guard-in-julia/1505
**Category:** General Usage
**Tags:** question
**Created:** [January 16, 2017, 4:52am UTC](https://discourse.julialang.org/t/import-guard-in-julia/1505 "2017-01-16T04:52:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kdmurray91](https://avatars.discourse-cdn.com/v4/letter/k/91b2a8/32.png) [@kdmurray91](https://discourse.julialang.org/u/kdmurray91)
#### Post date: [January 16, 2017, 4:52am UTC](https://discourse.julialang.org/t/import-guard-in-julia/1505/1 "2017-01-16T04:52:51Z")

</div>

Hi all,

Apologies if I’m lacking google skills, but I’m unable to find a Julian equivalent of the following common python pattern:

```python
if __name__ == " __main__":
    run_my_main_func()

```

This construct prevents code being executed when `import`-ing in python.

I’m developing a few bespoke scripts in julia, with nearly all functionality separated into bite-sized functions. For debugging purposed, I’d like to `include("thescript.jl")` and run functions by hand, but I have `main(ARGS[1], ARGS[2])`-style code in there for CLI usage.

Cheers,  
Kevin

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)
#### Post date: [January 16, 2017, 5:23am UTC](https://discourse.julialang.org/t/import-guard-in-julia/1505/2 "2017-01-16T05:23:03Z")

</div>

See [Within a Julia script, can you tell whether the script has been imported or executed directly? - Stack Overflow](http://stackoverflow.com/questions/14462557/within-a-julia-script-can-you-tell-whether-the-script-has-been-imported-or-exec)

---

<div class="post-metadata">

### Author: ![kdmurray91](https://avatars.discourse-cdn.com/v4/letter/k/91b2a8/32.png) [@kdmurray91](https://discourse.julialang.org/u/kdmurray91)
#### Post date: [January 16, 2017, 6:08am UTC](https://discourse.julialang.org/t/import-guard-in-julia/1505/3 "2017-01-16T06:08:27Z")

</div>

Thanks, and sorry for my inability to google!

EDIT:

It looks as though that is specific to the REPL. While this solves my current issue, like the original stack overflow poster, I’d like to know if there is a way to tell if a file has been `include()`-ed or imported.

---

<div class="post-metadata">

### Author: ![tkelman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkelman/32/692_2.png) [@tkelman](https://discourse.julialang.org/u/tkelman)
#### Post date: [January 16, 2017, 6:56am UTC](https://discourse.julialang.org/t/import-guard-in-julia/1505/4 "2017-01-16T06:56:42Z")

</div>

Try something like `if PROGRAM_FILE == @ __FILE__ ` ?

---

<div class="post-metadata">

### Author: ![kdmurray91](https://avatars.discourse-cdn.com/v4/letter/k/91b2a8/32.png) [@kdmurray91](https://discourse.julialang.org/u/kdmurray91)
#### Post date: [January 16, 2017, 9:41am UTC](https://discourse.julialang.org/t/import-guard-in-julia/1505/5 "2017-01-16T09:41:36Z")

</div>

Between the two, that looks like it will work. Thanks both!

---

<div class="post-metadata">

### Author: ![nmoran](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nmoran/32/11901_2.png) [@nmoran](https://discourse.julialang.org/u/nmoran)
#### Post date: [March 9, 2020, 1:10pm UTC](https://discourse.julialang.org/t/import-guard-in-julia/1505/6 "2020-03-09T13:10:03Z")

</div>

> [@tkelman](#):
>
> if PROGRAM\_FILE == @ **FILE**

Running into problems with this as the `PROGRAM_FILE` is the relative path and the `@_FILE__` is the absolute path. Running from command line using

```julia
julia --project=. bin/foo.jl

```

---

<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 9, 2020, 1:11pm UTC](https://discourse.julialang.org/t/import-guard-in-julia/1505/7 "2020-03-09T13:11:53Z")

</div>

See [Julia Python equivalent of \_\_main\_\_? - #2 by fredrikekre](https://discourse.julialang.org/t/julia-python-equivalent-of-main/35433/2).
