Is there any way you can import local procs from other files in the same directory?

Viewed 303

If you have 2 Python files in the same directory, you can do the following:


something.py

def returnSomething():
    return True

index.py

from something import returnSomething

test=returnSomething()

Can something similar be done in Nim by calling their procs?

1 Answers

Yes, you can, you just need to export the proc by adding * (the export marker) after the name of it - https://nim-lang.org/docs/manual.html#procedures-export-marker :)

# something.nim
proc returnSomething*(): bool = 
  result = true
# index.nim
import something

test = returnSomething()

You can also replace import something with from something import returnSomething, but it's a personal preference.

I think it might be good for you to read https://narimiran.github.io/nim-basics/ which covers most of Nim basics :)

Related