# How to include into local scope?

**URL:** <https://discourse.julialang.org/t/how-to-include-into-local-scope/34634>\
**Category:** General Usage\
**Created:** [February 14, 2020, 3:58pm UTC](https://discourse.julialang.org/t/how-to-include-into-local-scope/34634 "2020-02-14T15:58:15Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 14, 2020, 4:51pm UTC](https://discourse.julialang.org/t/how-to-include-into-local-scope/34634/11 "2020-02-14T16:51:03Z")

</div>

> [@HenrikM](#):
>
> Maybe we are talking past each other here. In C—which the preprocessor is an integral part of—an `#include` does exactly what I want.

Sure, you can do that in Julia too.

```julia
macro include(filename::AbstractString)
    path = joinpath(dirname(String( __source__.file)), filename)
    return esc(Meta.parse("quote; " * read(path, String) * "; end").args[1])
end

```

then

```julia
let x = 5
    @include "wowPlot.jl"
end

```

or

```julia
function f(x)
    @include "wowPlot.jl"
end

```

will do what you expect (i.e. act as if you pasted the included code at that point). (@oxinabox had the same idea and was a bit quicker to post, but I had a chance to test mine and I believe it works.)

(I wouldn’t recommend this from a maintenance/reability standpoint, however! And even for short-term hacks I think it is better to write functions as soon as you find yourself re-using code.)

---

_[View the full topic](https://discourse.julialang.org/t/how-to-include-into-local-scope/34634)._
