Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

Happy new year, dear community.

I bother you so early this 2020 with a kind of silly question.

Question: How to import a file with definitions properly?

Explanation:

I have on a folder two files, say header.cnb and calculation.cnb. In the header file I keep a lot of definition of expressions and functions, which will be used in calculation.

I try to import the header as (i.e. in the first lines of calculation)

from header import *

And worked! (hurray), but not always. It seems to depend on whether I open cadabra from the application panel or the CLI... or even worst, it depends on the pwd!

Then I try

import sys
sys.path.insert(0,r'/global/path/to/folder')
from header import *

and worked!... but again, it stop working on a next session.

Even try:

import os
os.system("cadabra2 /home/oscar/Documents/LatexFiles/UTFSM/Papers/cadabra-gravity/tutorials/header.cnb")

and

import os
os.system("cadabra2 header.cnb")

and

import os,sys
scriptpath = "../folder/"
sys.path.append(os.path.abspath(scriptpath))
import header
closed with the note: The second try works. The issue raise due to a bad code line in `header`.
in General questions by (15.0k points)
closed by
...