Julia 使用如何使用相对路径的一个例子

1.

首先可以看下如下的解释

help?> @__DIR__
  @__DIR__ -> AbstractString

  Expand to a string with the absolute path to the directory of the file
  containing the macrocall. Return the current working directory if run from a
  REPL or if evaluated by julia -e .

help?> joinpath
search: joinpath

  joinpath(parts...) -> AbstractString

  Join path components into a full path. If some argument is an absolute path
  or (on Windows) has a drive specification that doesn't match the drive
  computed for the join of the preceding paths, then prior components are
  dropped.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> joinpath("/home/myuser", "example.jl")
  "/home/myuser/example.jl"
2.

假如我们有个包 Mypackage/,有如下结构

Mypackage/test/test.jl
Mypackage/src/mymoudel.jl

那么在 test.jlinclude mymoudel.jl 时,需要在 test.jl 中写入 include( joinpath(@__DIR__, "..", "src", "mymoudel.jl") ).

在 Julia 中文论坛 中也有这样一个例子: 使用using引用其他路径下的文件报错.

你可能感兴趣的:(Julia)