Call functions with the same names from different files

Hi,

I have a file where I include files:

include("./path/File1.jl")
include("./path/File2.jl")

and then I want to call functions from these files, and since they have the same name, i wanted to use the file’s names as discriminators:

File1.function()
File2.function()

These are my functions, so I can just change their names and it’ll be good, but is it possible to achieve what I’m trying to?

You are looking for Modules: Modules · The Julia Language
A distinction based on the source file name is not possible (AFAIK).

1 Like

Conceptually, the include keyword just copy-pastes the code in the target file. Unlike Python’s import, it does not create a separate namespace (or module): in Julia, namespaces and files are disconnected.

If you really prefer Python-like behavior, take a look at GitHub - Roger-luo/FromFile.jl: Julia enhancement proposal (Julep) for implicit per file module in Julia

1 Like

See also Best practise: organising code in Julia - #2 by stevengj

2 Likes

You may be interested in GitHub - Roger-luo/FromFile.jl: Julia enhancement proposal (Julep) for implicit per file module in Julia

1 Like