Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No support for pathlib.Path on model loading #258

Open
matthiaskoenig opened this issue Jul 26, 2020 · 0 comments
Open

No support for pathlib.Path on model loading #258

matthiaskoenig opened this issue Jul 26, 2020 · 0 comments

Comments

@matthiaskoenig
Copy link
Contributor

Paths from pathlib should be supported in file/model loading.
Currently, only strings and file handles are supported.

/home/mkoenig/envs/fbc_curation_py37/lib/python3.7/site-packages/cameo/visualization/plotting/__init__.py:52 UserWarning: Cannot import any plotting library. Please install one of 'plotly', 'bokeh' or 'ggplot' if you want to use any plotting function.
Traceback (most recent call last):
  File "/home/mkoenig/git/fbc_curation/fbc_curation/cameo_solver.py", line 20, in <module>
    model = load_model(model_path)
  File "/home/mkoenig/envs/fbc_curation_py37/lib/python3.7/site-packages/cameo/io.py", line 66, in load_model
    raise ValueError('Provided argument %s has to be either a string or a file handle' % path_or_handle)
ValueError: Provided argument /home/mkoenig/git/fbc_curation/fbc_curation/examples/models/e_coli_core.xml has to be either a string or a file handle

On loading model via path

from fbc_curation import EXAMPLE_PATH

model_path = EXAMPLE_PATH / "models" / "e_coli_core.xml"

# 01 objective value
from cameo import load_model
model = load_model(model_path)

The modern way of handling paths is using pathlib. It can be used as a replacement for file handles in the open statements, so pretty easy to support by just allowing pathlib Path in addition to file handles.
https://docs.python.org/3/library/pathlib.html

Best Matthias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant