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

Python coding suggestions #545

Open
falkamelung opened this issue Jul 12, 2024 · 0 comments
Open

Python coding suggestions #545

falkamelung opened this issue Jul 12, 2024 · 0 comments

Comments

@falkamelung
Copy link
Member

Falk:
Useful code snippets from Kawan's run_plot_precipitation_all.py :

https://github.com/geodesymiami/Precip_cron/blob/9ca7d19f937e7dce45b548a8cd61ebe832690fe3/run_plot_precipitation_all.py#L13-L16

https://github.com/geodesymiami/Precip_cron/blob/9ca7d19f937e7dce45b548a8cd61ebe832690fe3/run_plot_precipitation_all.py#L44-L47

https://github.com/geodesymiami/Precip_cron/blob/9ca7d19f937e7dce45b548a8cd61ebe832690fe3/run_plot_precipitation_all.py#L88

Kawan:
Regarding the last point, there are two ways to initialize an argparse.Namespace.

The way I did it in run_plot_precip… is:

inps = argparse.Namespace(style=style, name=[volcano], no_show=True)

import argparse
kwargs = {'key':'value', 'hello':'world', 'im_not': 'paid_enough’}

option 1

argparse.Namespace(** kwargs)
Namespace(key='value', hello='world', im_not='paid_enough’)

option 2

argparse.Namespace(key='value', hello='world', im_not='paid_enough')
Namespace(key='value', hello='world', im_not='paid_enough’)

But result is the same object. But passing **kwargs is great when you have a lot of key word arguments or want to pass things dynamically.

This is also the case for (or any other object with a similar init method).

https://github.com/python/cpython/blob/e8c91d90ba8fab410a27fad4f709cc73f6ffcbf4/Lib/argparse.py#L1295-L1297

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