Code Monkey home page Code Monkey logo

Comments (2)

caglorithm avatar caglorithm commented on August 22, 2024

Still don't know how to solve this in the best way. This is what I've been imagining:
Ideally, the user could do

import neurolib
print(neurolib.models)

and get a list of the model's module names (e.g., neurolib.models.aln), and the name and the description attribute of each model.

This gets the name of all submodules for example (in neurolib/__init__py). But then? Do I need to import them to get the attributes of each model class? Seems a bit overkill.

import pkgutil
import neurolib.models

package = neurolib.models

models = []
for _, modname, _ in pkgutil.walk_packages(
    path=package.__path__, prefix=package.__name__ + ".", onerror=lambda x: None
):
    if modname.split(".")[-1] == "model":
        models.append(modname)

image

Obviously the easiest way would be to hardcode a list. But that's not fun, innit?

from neurolib.

jajcayn avatar jajcayn commented on August 22, 2024

I think you actually need to import them in order to get the info stored in the class itself... so some packages define something like __all__ = [] as a list in some __init__ file which also then can work like "from neurolib.models import *" and it'll import only stuff that is inside __all__...
that can be also used to print out available models I guess?

however, print(neurolib.models) won't work I am afraid..

from neurolib.

Related Issues (20)

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.