fildred13 fildred13 - 10 months ago 37
Python Question

Does any standard Python3 object have a get method that doesn't have positional arguments?

I am trying to figure out how to use a barely documented feature of a poorly documented API. I have distilled the chunk of code that is giving me trouble down to this for simplicity:

def build_custom_args(args):
custom_args = {}
for key in args:

I can tell from the function that constructs
that it is a list. Problem is, a list of what? No matter what I put in the list, key.get() raises one exception of another.

For example, if I execute that code like so:
then I get an understandable error message:
AttributeError: 'str' object has no attribute 'get'

Or, try a dictionary:
build_custom_args([{'foo': 'bar'}])
, but the error is raised:
TypeError: get expected at least 1 arguments, got 0

As best I can tell
is a list of some standard python objects - there is no indication that these are special objects with a custom

Am I missing something obvious? Is there some standard python object that has a
method which takes no positional arguments? Is this a syntax of some older version of Python? Or have I found a bug in the API?

Answer Source

Well... I found this in the github link you have provided

class Email(object):
    # code... 

    def get(self):

Matter of fact, a lot of those classes have get methods.

Since Python is duck typed, there isn't really a way to determine what object is correct, but you're just building a dictionary, so shouldn't matter too much