1 数组截取
a = "Hello"
a[1:4] 输出结果:ell
a[:4] 输出结果:Hell
a[1:] 输出结果:ello
2 数组操作
str1 = "avca"
str2 = "bvcb"
str0 = ""
str4 = None
str3 = "cvcc"
disease = []
disease.append(str1)
disease.append(str2)
disease.append(str0) if str0 else ''
disease.append(str4) if str4 else ''
disease.append(str3)
print(",".join(disease))
mongodb得多条件查询
myclient = pymongo.MongoClient(host=config.mongodb_ip, port=57017)
mydb = myclient[config.mongodb_db]
mycol = mydb[type]
x = mycol.find({"$or":[{"illness":{"$regex":"COPD"}},{"illness":{"$regex":"慢阻肺"}},{"illness":{"$regex":"慢性阻塞性肺疾病"}},{"illness":{"$regex":"肺气肿"}}]})
x为list,循环取出即可
python json转字符串汉字处理
# 默认情况下使用json.dumps会将汉字转换为ascii编码
json.dumps(_str["list"])
# 使用时常不会让其编码,则需要添加下面参数
json.dumps(_str["list"], ensure_ascii=False)