Giter Club home page Giter Club logo

Comments (3)

petercorke avatar petercorke commented on June 15, 2024

You can specify a function name in the block, but that function must be in scope when the .bd file is executed. You can do this with a MAIN block that references a Python program that defines or imports the functions that you need. This is a bit complex and not as well documented as it should be. There are examples of how this works here and useful detail in the README.md file.

from bdsim.

mars-seo avatar mars-seo commented on June 15, 2024

Yeap, I already checked that, and somehow I managed it.

I edited functions.py like below.

# file location like XX.py
py_md = "/xx/xx/XX.py"
fn_name = "private_func"
# OR
py_md = "numpy.linalg"
fn_name= "pinv"

split_point = py_md.split('.')
if split_point[-1] == "py":
    split_slash = py_md.split('/')
    module_name = split_slash[-1].split('.')
    spec = importlib.util.spec_from_file_location(module_name[0], py_md)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    class_ = getattr(module, cls_name, None)()
    func = getattr(class_, method, None)
else:
    module = importlib.import_module(py_md)
    class_ = getattr(module, cls_name, None)()
    func = getattr(class_, method, None)

It worked, but we made the decision not to use bdsim anymore.

from bdsim.

petercorke avatar petercorke commented on June 15, 2024

What are you using instead?

from bdsim.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.