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

Feature request: only one function for loading files #225

Open
thmsklngr opened this issue Aug 9, 2022 · 3 comments
Open

Feature request: only one function for loading files #225

thmsklngr opened this issue Aug 9, 2022 · 3 comments

Comments

@thmsklngr
Copy link

Hi,

another idea which came into my mind is to provide just one function for loading data into an instance. Currently there are a number of class methods for creating a new instance with a type of file, i.e. from_json, from_yaml, etc.

This could be simplified with one function and parse the file according the extension or an optional keyword parameter:

>>> config = Box.from_file('/this/is/my/datafile.yml')
# or
>>> config = Box.from_file('/this/is/my/datafile.txt', file_type='yaml')

Just an idea, I had a similar implementation in my own config parser, but not as sophisticated like your package python-box. It's really, really great, thanks for the efforts.

Regards, Thomas

@cdgriffith
Copy link
Owner

Sorry for delay, This is actually already / still in discussion #195 . Feel free to add thoughts there!

@cdgriffith
Copy link
Owner

I am also an IDIOT and forgot about my own code. There is box_from_file already!

https://github.com/cdgriffith/Box/blob/master/box/from_file.py#L94-#L96

from box import box_from_file

box_from_file(".black.toml") 

# Box({'tool': {'black': {'line-length': 120, 'target-version': ['py36', 'py37', 'py38'])

@cdgriffith
Copy link
Owner

To clarify why it isn't a class function of, it's meant to be more powerful that it can return either a Box or BoxList as needed.

I am re-opening this becausse I need to add better docs for this in the wiki

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

No branches or pull requests

2 participants