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

Consider to support context manager (with) #17

Open
ecomodeller opened this issue Feb 1, 2024 · 0 comments
Open

Consider to support context manager (with) #17

ecomodeller opened this issue Feb 1, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@ecomodeller
Copy link
Member

data_access.open_database()

Instead of:

data_access.open_database()
muids = data_access.get_muid_where("msm_Link", "MUID='link_test'")
data_access.close_database()

it will be

with data_access.open_database()
    muids = data_access.get_muid_where("msm_Link", "MUID='link_test'")
    ...
# db connection is closed at the end of the with block

Closing databases is typically done with automatically with a context manager.
https://realpython.com/python-with-statement/#the-with-statement-approach

Equivalent to using in C# https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using

@ecomodeller ecomodeller added the enhancement New feature or request label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant