# Import of commands from txt file to cnb

+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;


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.

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 (52.9k points)
 #!/usr/local/bin/cadabra2

cadabra2 file.txt