python2.7 - python json 多态问题
天蓬老师
天蓬老师 2017-04-17 14:31:55
0
1
297

import json

class Students(object):
def read(self):
print r'["Tim","Bob","Alice"]'
s = Students()

print json.load(s)
结果输出来但是出现警告Traceback (most recent call last)
但是如果把print换成return就好了 这是为什么呢

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

répondre à tous(1)
黄舟
json.load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]])¶
Deserialize fp (a .read()-supporting file-like object containing a JSON document) to a Python object using this conversion table.

json.load方法是读一个file-like对象的read方法的返回值,所以要在read方法里返回一个json字符串,打印是不行的。

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!