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

Ability to check if string is a valid unit (in any unit system) #30

Closed
langmm opened this issue Jul 14, 2018 · 0 comments
Closed

Ability to check if string is a valid unit (in any unit system) #30

langmm opened this issue Jul 14, 2018 · 0 comments

Comments

@langmm
Copy link

langmm commented Jul 14, 2018

  • unyt version: 1.0.4
  • Python version: 2.7-3.6
  • Operating System: MacOSX

Description

It would be awesome to be able to check if a string is a valid unit by something like:

if 'something' in ureg:
    ...

What I Did

Currently, you can get this by using try, except, but it would be useful out-of-the-box in a more pythonic way.

def is_unit(unit_string):
    try:
        unyt.Unit(ustr)
    except unyt.exceptions.UnitParseError:
        return False
    return True
@ngoldbaum ngoldbaum changed the title Ability to check if string is a valid unity (in any unit system) Ability to check if string is a valid unit (in any unit system) Jul 14, 2018
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