gpt4 book ai didi

python 文件返回 No such file or directory

转载 作者:太空狗 更新时间:2023-10-29 11:33:41 26 4
gpt4 key购买 nike

我写了一个 python 脚本来查询 freebase 一个开源数据库。我在windows中编写了文件并将其移植到linux。我已经更改了文件的权限并添加了适当的 header ,但 linux shell 返回为:

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()

最佳答案

我最近遇到了同样的问题。问题是移植文件的文件格式仍然是dos格式,并且包含特殊字符。在脚本文件命令上运行 dos2unix 解决了问题。

关于python 文件返回 No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12412616/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com