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

How to make Cadabra accept/incorporate the code prepared in plain text, for example in 'example.txt' file?

I'm not asking for the reading one line after another (https://cadabra.science/notebooks/ref_import.html) as inside I have not only definitions of variables... Probably I should expect something like:

 with open("Cadabra1.txt") as file:
     content = file.read()
content;

I have a Mathematica procedure generating thousands of txt files, each having properly designed code, which separately copied/pasted into opened Cadabra notebook allows me to run it in Cadabra. I need something to change this list of commands in each txt file into true Cadabra cnb files...

Naturally, I have tried to mimic inside of the Cadabra JSON but something goes wrong.

asked in General questions by (250 points)

2 Answers

+2 votes

If you have a text file Cadabra1.cdb with Cadabra code, you can read that in using

 from Cadabra1 import *

The file needs to be in your PYTHONPATH (or in the current directory, which Cadabra adds to PYTHONPATH on startup).

Pull the latest Cadabra version from github to fix an error which led to suppression of all output after such an import statement.

answered by (57.8k points)
0 votes

Finally, I have sorted out things by generating the txt files with a list of commands appended by the line:

 #!/usr/local/bin/cadabra2

(therefore what would be a result of using in terminal "cadabra2cadabra example.cnb example.txt").

The last step for me was just running in a terminal:

cadabra2 file.txt
answered by (250 points)
...