# Rewrite Packages from Python

**URL:** <https://discourse.julialang.org/t/rewrite-packages-from-python/79888>\
**Category:** General Usage\
**Tags:** package\
**Created:** [April 23, 2022, 11:37am UTC](https://discourse.julialang.org/t/rewrite-packages-from-python/79888 "2022-04-23T11:37:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ordens\_Ritter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ordens_ritter/32/50363_2.png) [@Ordens\_Ritter](https://discourse.julialang.org/u/Ordens_Ritter)\
**Post date:** [April 23, 2022, 11:37am UTC](https://discourse.julialang.org/t/rewrite-packages-from-python/79888/1 "2022-04-23T11:37:04Z")

</div>

I am trying to advance my Julia language skill and (some concepts). Therefore am trying to work throw the book “Deep Learning and the Game of GO” but not writing the Code in Python but in Julia.

I get some problems with writing own packages and use it:  
I have a file called `manvbot.jl`

````julia

include("dlgo/DLGO.jl")

function main()
    boardsize = 9
    game = newgame(boardsize)
...

main()
``

with this file I wanna use a local package.

Folder: dlgo
Files: DLGO.jl, gotypes.jl, goboard_slow.jl, ...

As you can see I include the module from DLGO.jl
```julia
module DLGO

__precompile__ (false)

include("gotypes.jl")

include("goboard_slow.jl")

include("utils.jl")

include("agent/base.jl")

include("agent/helpers.jl")

include("agent/naive.jl")

export newgame

end

````

The problem is that I cannot find, the function newgame which is included in the file goboard\_slow.jl ( shorted version below)

```julia
mutable struct Move{}
    point::Point
    ispass::Bool
    isresign::Bool
end

struct GoString{}
    color::Player
    stones::Set{Point}
    liberties::Set{Point}
end

mutable struct Board{}
    numrows::UInt8
    numcols::UInt8
    grid::Set{Point}
end

mutable struct GameState
    board::Board
    nextplayer::UInt8
    previousstate::Union{GameState, Nothing}
    lastmove::Union{Move, Nothing}
end

function newgame(boardsize::UInt)
    board = Board(boardsize)

    return GameState(board, black, Nothing, Nothing)
end

```

I am wondering why I can’t find the file newgame function? Error: `ERROR: LoadError: UndefVarError: newgame not defined`

From my understanding I include the code from the file (including the function) in the modul as the full code/text, which I again do in the in manvbot.jl script. Why is the function than undefined? Do I have any misscontecptions?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 23, 2022, 11:55am UTC](https://discourse.julialang.org/t/rewrite-packages-from-python/79888/2 "2022-04-23T11:55:00Z")

</div>

> [@Ordens\_Ritter](#):
>
> The problem is that I cannot find, the function newgame which is included in the file goboard\_slow.jl ( shorted version below)

You’ll want to use `using .DLGO` as well there, after the `include(...)`:

> [@Ordens\_Ritter](#):
>
> ```julia
> include("dlgo/DLGO.jl")
> 
> function main()
> boardsize = 9
> game = newgame(boardsize)
> ...
> 
> main()
> 
> ```

Then it should work & find the exported method. The reason for this is that what matters for namespacing is the `module Name .. end` part, NOT the file name/directory structure, as is the case in python.

---

<div class="post-metadata">

**Author:** ![Ordens\_Ritter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ordens_ritter/32/50363_2.png) [@Ordens\_Ritter](https://discourse.julialang.org/u/Ordens_Ritter)\
**Post date:** [April 23, 2022, 12:05pm UTC](https://discourse.julialang.org/t/rewrite-packages-from-python/79888/3 "2022-04-23T12:05:26Z")

</div>

> [@Sukera](#):
>
> work & find the exported method.

Thanks for your reply:  
I added the line: `using DLGO` after the include statement. But I get the error:

```julia
ERROR: LoadError: ArgumentError: Package DLGO not found in current path:
- Run `import Pkg; Pkg.add("DLGO")` to install the DLGO package.

```

Which I think is kind of strange, because I am able to do the include statement.  
the calling script is in the same path as the folder dlgo. The folder contains some files as DLGO.jl as shown before.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 23, 2022, 12:19pm UTC](https://discourse.julialang.org/t/rewrite-packages-from-python/79888/4 "2022-04-23T12:19:47Z")

</div>

`using .DLGO` with a dot, it means the module was defined in the current scope

---

<div class="post-metadata">

**Author:** ![Ordens\_Ritter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ordens_ritter/32/50363_2.png) [@Ordens\_Ritter](https://discourse.julialang.org/u/Ordens_Ritter)\
**Post date:** [April 23, 2022, 3:50pm UTC](https://discourse.julialang.org/t/rewrite-packages-from-python/79888/5 "2022-04-23T15:50:13Z")

</div>

One extra, how do I solve the problem within the package.

when I define some Constructor (for example) in File A and wanna use it in B of the module.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [April 23, 2022, 4:04pm UTC](https://discourse.julialang.org/t/rewrite-packages-from-python/79888/6 "2022-04-23T16:04:31Z")

</div>

If they’re all in the same module, it should be directly accessible as long as you `include` the relevant files. You don’t have to have a module per file.

---

<div class="post-metadata">

**Author:** ![Ordens\_Ritter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ordens_ritter/32/50363_2.png) [@Ordens\_Ritter](https://discourse.julialang.org/u/Ordens_Ritter)\
**Post date:** [June 2, 2022, 12:50pm UTC](https://discourse.julialang.org/t/rewrite-packages-from-python/79888/7 "2022-06-02T12:50:28Z")

</div>

There is some problem with include, though.

I have a file A.jl and file B.jl.

A.jl contains structures and functions for these. But some functions are calling B.jl which uses some definitions of the struts of A.jl

So both file includes the other. How do I solve this loop problem besides from separating the type from its functions?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [June 2, 2022, 12:53pm UTC](https://discourse.julialang.org/t/rewrite-packages-from-python/79888/8 "2022-06-02T12:53:47Z")

</div>

I would suggest splitting into a third file “C.jl” which contain the functions that depend on both the things that are defined in A and B. This is how this structure would have to be if those where packages, otherwise you would have a circular dependency. And then include the files in order.
