我寫了一個python腳本來查詢freebase一個開源數據庫。我在windows中編寫文件並將其移植到linux。我已經改變了該文件的權限,並添加相應的頭還沒有在Linux shell收益爲:python文件返回爲沒有這樣的文件或目錄
No such file or directory
這裏的文件:
#! /usr/bin/env python
import urllib
import string
#query freebase to find results containing graduates from the University of Texas
query1=[{
"name": null,
"type": "/people/person",
"!/education/education/student": [{
"!/education/educational_institution/students_graduates": [{
"id": "/en/university_of_texas"
}]
}]
}]
query2=[{
"id": "/en/university_of_texas",
"/education/educational_institution/students_graduates": [{
"student": {
"name": null
},
"degree": {
"name": null
},
"end_date": null,
"major_field_of_study": [{
"name": null
}]
}]
}]
html = urllib.urlopen("https://www.googleapis.com/freebase/v1/mqlread?query="+query2)
library = json.loads(html)
name_dic = {}
for e in library["result"]:
name_dic[e["student"]["name"]] = [e["degree"]["name"],int(e["end_date"]),e["major_field_of_study"][0]["name"]]
conn = sqlite3.connect('data.db')
c = conn.cursor()
t=[]
for key in name_dic.iterkeys():
t.append((key, name_dic[key][0],name_dic[key][1],name_dic[key][2]))
try:
c.executemany('insert into people values(?,?,?,?)',t)
print "entities found and saved"
except sqlite3.IntegrityError:
for k in t:
try:
c.execute('insert into people values (?,?,?,?)',k)
print (str(k[0])+" was added")
except sqlite3.IntegrityError:
print "Could not save entities"
conn.commit()
什麼給你'沒有這樣的文件或目錄'? –
檢查文件系統上是否實際上有/ usr/bin/env –
腳本有幾個語法錯誤(例如'null'),所以它必須是解釋器。 –