I am attempting to use IronPython 3.4 with my C# / .NET MAUI project. As IronPython 3.4 is pretty new, I am not sure if there is much support for it yet.
As a part of experimentation, I am attempting to list the directory I am using. However, the os module does not seem to be found when I run the code.
Another StackOverflow post suggested adding the IronPython lib folder. However - I have two questions. They are using IronPython 2.7 - is it the same for 3.4? Also, would this be compatible with a .NET MAUI project? How would I include the lib folder so that it works across devices (not just on my machine)? I would think that adding IronPython as a Nuget package would solve that issue. I don't have IronPython installed yet system-wide. Would I need to do that?
Here is the code I am running which is used for the MAUI page, and attempts to list the contents of a directory:
using Microsoft.Maui.Controls;
namespace MauiSolver
{
public partial class SolveCryptogramPage : ContentPage
{
public SolveCryptogramPage()
{
InitializeComponent();
}
private void OnSubmitButtonClicked(object sender, EventArgs e)
{
var engine = IronPython.Hosting.Python.CreateEngine();
var scope = engine.CreateScope();
string lsCommand =
"import os" + "\n" + "print(os.listdir('.'))";
engine.Execute(lsCommand, scope);
DisplayLabel.Text = "This feature is not yet implemented.";
}
}
}
For clarification, I am attempting to list the directory to see how I would call a script in a subfolder of my project that solves cryptograms. I think I know how to make sure that file is included in the build process (in the Visual Studio file properties). Am I going about that the right way so far? Is there another StackOverflow article that could help with that? Thanks. I am also doing my own research.
If it helps, I am using aquach's cryptogram solver. The command I need to run in C# is:
python3 sub_solver.py sample_input.txt -c english_corpus_generator/corpus.txt
Eventually I will need to save the user's input string to a text file for how the script works, as well as make a substring of the output to only return the solved string.