0

Hello StackOverflow Community,

I am a beginner Python programmer who is transitioning over from MATLAB. One of my biggest struggles so far has been trying to understand how to find out more information about new Python packages that I install. Let me attempt to give a concrete example below:

Say I download and want use the pygrib package to open and grab some atmospheric data from a .grib file I downloaded. I find some code online (here) that shows me how to grab data using pygrib. The author of that code uses syntax for the pygrib package that I just can't to find documented on the pygrib website (e.g. pygrib.open.select.values(); pygrib.open.select()["latitudeOfFirstGridPointInDegrees]).

When searching for more information on pygrib.open.select.values() on the pygrib website (here) I see that pygrib.open.select() takes **kwargs as its argument, and nothing further is explained.

My question here is, are kwargs and .values the same thing in Python? As in, is the .values a key word argument for pygrib.open.select()? My thoughts lead to the answer no, which then brings up another question:

Where can one find more information about the kwargs that pygrib.open.select()accepts, and in general how can one find this information for other Python packages? Would it be a matter of looking at the source code for each class?

Any help or guidance is sincerely appreciated. Thank you for your time and efforts.

mariandob
  • 15
  • 4
  • Keyword args syntax is well documented in general: https://www.geeksforgeeks.org/args-kwargs-python/. This specific use of kwargs appears to be filtering based on certain keys in the data. Have you tried calling `grb.keys()` (where `grb` is a `gribmessage` value as returned by `pygrib.open.select()`) to find the things that can be used to as `kwargs` in the `pygrib.open.select()` method? – Oli Jan 28 '20 at 00:32
  • @Oli, Thanks for your response! I never knew about the `.keys()` method in Python. I was able to look through some `**kwargs` for my data. How does someone usually find methods like this one? Say for instance, in my example If I wanted to find information about the `pygrib.open.select.values()` method, where would I look? The pygrib documentation doesn't seem to have anything about it, as it only provides info up to `pygrib.open.select()`. I feel as if there's a bunch of other packages where I struggle to find such information and thus my understanding of such packages is limited. – mariandob Jan 28 '20 at 04:03
  • (1) You need to know about Python and what types of thing everything is, e.g. `pygrib` is a module `pygrib.open` is a class `pygrib.open.select` is is a method (all this is in the docs). (2) Now that you know `pygrib.open.select` is a method, check what it returns in the docs: a `gribmessage`. (3) Look up `gribmessage` in the docs and you will find the `gribmessage.keys` method. – Oli Jan 29 '20 at 14:47
  • There is no special place I look to find this info it's more about knowing how to use the docs. That being said, it doesn't look like the `gribmessage.values` is well documented, the only relevant thing I can see is in the `gribmessage.__getitem__` method (a special Python method that allows things like `grb["some key"]`) where values is mentioned. – Oli Jan 29 '20 at 14:52
  • @Oli, thanks tremendously for your help and for your time spent writing this information. It helped clarify some things for me and also identified some fundamental weaknesses in my understanding which I need to work on. If you want to paste togeather your comments and post it as a single answer I will gladly accept it. – mariandob Jan 30 '20 at 17:16
  • You're welcome, good luck on your Python-learning journey! – Oli Jan 31 '20 at 18:38

1 Answers1

0

Keyword args syntax is well documented in general: geeksforgeeks.org/args-kwargs-python. This specific use of kwargs appears to be filtering based on certain keys in the data. Have you tried calling grb.keys() (where grb is a gribmessage value as returned by pygrib.open.select()) to find the things that can be used to as kwargs in the pygrib.open.select() method?

How does someone usually find methods like [gribmessage.keys]?

  1. You need to know about Python and what types of thing everything is, e.g. pygrib is a module, pygrib.open is a class and pygrib.open.select is is a method (all this is in the docs).
  2. Now that you know pygrib.open.select is a method, check what it returns in the docs: a gribmessage.
  3. Look up gribmessage in the docs and you will find the gribmessage.keys method.

How does someone usually find methods like this one? Say for instance, in my example If I wanted to find information about the pygrib.open.select.values() method where would I look?

There is no special place I look to find this info; it's more about knowing how to use the docs. That being said, it doesn't look like the gribmessage.values method is well documented, the only relevant thing I can see is in the gribmessage.__getitem__ method (a special Python method that allows things like grb["some key"]) where values is mentioned.

Oli
  • 2,507
  • 1
  • 11
  • 23