fusion-engineering / inline-python

Inline Python code directly in your Rust code
https://docs.rs/inline-python
BSD 2-Clause "Simplified" License
1.15k stars 37 forks source link

Can I load python file inside context #24

Closed hyousefGopher closed 4 years ago

hyousefGopher commented 4 years ago

Instead of writting:

    c.run(python! {
        x = 123
        print("python: x =", x)
        rust_print(x)
    });

Can I write something like:

    c.run(python! {
        load_python_file("file.py")
    });

Where "file.py" is:

x = 123
print("python: x =", x)
rust_print(x)
m-ou-se commented 4 years ago

If you want to know how to load Python files from Python code, check the Python documentation. That's not related to inline-python.

hyousefGopher commented 4 years ago

I tried like this:

c.run(python!  {
                    from fox import load
                    load()
                })

tried saving my fox.py file at the root directory, as well as at the src directory, but in both cases I got:

  File "src\main.rs", line 41, in <module>
    from fox import load
ModuleNotFoundError: No module named 'fox'

So not sure what is the correct location to save the file in!

m-ou-se commented 4 years ago

You'll need to add the path in sys.path in Python.