I'm coming from a Java background and thought I'd try some Python today, so perhaps you can keep that in mind when explaining :)
I do the following:
resp = requests.get(url, headers=headers)
something = jsonpickle.unpickler.decode(resp.text)
Server responds fine (with Json content). I (think I) understand that something is a dict because type(something) gives me <class 'dict'>.
The documentation for the decode method though says the return type is Any.
What's happening there?
Also, this document lists a couple of methods for dict like dict.clear() which PyCharm does not offer me on my something dict.
Why is that?
1 个答案:
答案 0 :(得分:3)
It decodes whatever it is given to a python object (in this case it is a dict),but it could be a list, or an int or a float or a string or a handful of other basic types. you could also get the json back with resp.json()(probably im not sure what jsonpickle is it may be more than just json) ....
you must tell pycharm it is a dict otherwise pycharm has no way of knowing what that method will return. for pycharm to know you can do this with
assert isinstance(something,dict)