Can I run output of Python code/text file in Julia?

Viewed 46

I wrote a python script that generates a tree and outputs some variable creation and function calls in Julia syntax to a text file (I am testing the correctness of some Julia tree algorithms in phylogenetics). I was wondering if there is a way to "run" the text file in a Julia Jupyter notebook? It gets tedious to manually copy the file and run it as I am generating many files.

1 Answers

You can run include("treealgos.jl") in a Jupyter cell, to run the entire file there. It's equivalent to copy-pasting the file contents to that cell, and all the variables and functions defined in the file become available in the notebook after that.

Note that this is very different from using or importing a module, which require a module name and come with extra features like namespacing and exports. An include in contrast is a more basic and simpler feature, similar to a #include in C language, just bringing the code that was included into wherever the include statement happens to be.

Related