각 값을 Google 검색 API로 보내기 전에 CSV 파일을 찾아보고 그 CSV 파일을 구문 분석 할 수있는 함수를 작성하려고합니다. 비트가 이미 쓰여졌습니다).계속 "NoneType 객체가 subscriptable이 아닙니다."
def loadtemplate():
filename = tkFileDialog.askopenfilename(filetypes = (("CSV files", "*.csv")
,("Text Files", "*.txt")
,("All files", "*.*")))
if filename:
try:
csvfile = csv.reader(open(filename, 'rb'), delimiter=',')
for row in csvfile:
for x in row:
generate(x)
except:
tkMessageBox.showerror("Open Source File", "Failed to read file \n'%s'"%filename)
return
을 그리고 내 CSV 파일은 다음과 같습니다 :
그래서 지금 나는이있어seo,company name,drupal,wordpress themes,awesome web design
아무것도 너무 미친. 어쨌든이 오류가 발생합니다 :
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:/Python27/Projects/Google Searcher/realsearcher.py", line 20, in loadtemplate
generate(x)
File "C:/Python27/Projects/Google Searcher/realsearcher.py", line 31, in generate
gs = gs['cursor']
TypeError: 'NoneType' object is not subscriptable
값이 None으로 설정되어있는 것 같습니다. 하지만 어느 쪽이든 if x == None:
조건부를 계속 사용하려고하면 쿼리가 통과하지 못하거나 CSV 파일을 구문 분석해야하는 곳으로 변경하려고 시도하지 않습니다.
여기에 무슨 일이 일어나고 있으며 어떻게 수정합니까? -
PS이 변수 행 모습입니다 :)
여기['seo', 'company name', 'drupal', 'wordpress themes', 'awesome web design']
이 (생성되어 나는 두 솔루션이 더 오래 걸릴 것이라고 할 것입니다 뭔가를 작성하고하는 것은 불필요한 것을 느꼈기 때문에 (I 중복 코드를 사용하기 때문에 이 프로젝트는) 확장되지 않습니다 :
def generate(item):
infoget = urllib.quote(item)
infoquote = '"' + infoget + '"'
response = urllib2.urlopen("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + infoget)
gs = simplejson.load(response)
gs = gs['responseData']
gs = gs['cursor']
gs = gs['estimatedResultCount']
print gs
response = urllib2.urlopen("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + infoquote)
gs = simplejson.load(response)
gs = gs['responseData']
gs = gs['cursor']
gs = gs['estimatedResultCount']
print gs
생성 기능은 무엇을 수행합니까? 그 코드를 보여줄 수 있습니까? – Junuxx
글쎄, gs 변수는 subscriptable이 아닙니다 (즉, 사전이나 유사한 데이터 구조가 아닙니다). API에서 "생성"기능을 사용합니까, 아니면 귀하의 코드입니까? –
generate 함수는 내 코드에서 가져온 것입니다. 나는 그것을 게시 할 것이다. –