mardi 14 août 2018

str.find == -1 but the string cant pass the if condition

#!/usr/bin/env python
# coding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import json
import requests
from chardet import detect

false = False
null = ""
true = True
#from werobot import client
file_path = 'data1.json'
with open(file_path) as f:
    js = f.read()

dic = eval(js)



def ana(month):
    i = len(dic["items"])-1
    st = ""
    while i > 0:
        #print dic["items"][i]["name"]

        if "联系电话" not in dic["items"][i]["name"] and "报题" not in dic["items"][i]["name"] and st.find(dic["items"][i]["name"]) == -1 and (month == dic["items"][i]["properties"]["lastModifiedDate"][0:2] or month == dic["items"][i]["properties"]["lastModifiedDate"][0:1]):
            #print st.find(dic["items"][194]["name"])

            st = st + dic["items"][i]["properties"]["lastModifiedDate"][0:4].replace("/",".")+" " + dic["items"][i]["name"] +str(i)+"\n"
            i = i - 1
        i = i - 1

    return st 
all_data = ana("7")

print all_data

st.find(dic["items"][194]["name"]) = -1,but it can't pass the if condition :st.find(dic["items"][i]["name"]) == -1

data1.json is on the gistdata1.json on gist

Is there anything wrong with this codes?

Aucun commentaire:

Enregistrer un commentaire