这是错误
[Running] python -u "/Users/thomasmciver/Desktop/chat/ai-chat.py"
File "/Users/thomasmciver/Desktop/chat/ai-chat.py", line 38
with open ('Users/thomasmciver/Desktop/chat/RC_2015-01.txt' buffering=1000) as f:
^
SyntaxError: invalid syntax
[Done] exited with code=1 in 0.051 seconds
这是我的代码
# This Python file uses the following encoding: utf-8
import sqlite3
import json
from datetime import datetime
timeframe = '2015-05'
sql_transaction = []
connection = sqlite3.connect('{}.db'.format(timeframe))
c = connection.cursor()
def create_table():
c.execute("CREATE TABLE IF NOT EXISTS parent_reply(parent_id TEXT PRIMARY KEY, comment_id TEXT UNIQUE, parent TEXT, comment TEXT, subreddit TEXT, unix INT, score INT)")
def format_data(data):
data = data.replace('\n',' newlinechar ').replace('\r',' newlinechar ').replace('"',"'")
return data
def find_parent(pid):
try:
sql = "SELECT comment FROM parent_reply WHERE comment_id = '{}' LIMIT 1".format(pid)
c.execute(sql)
result = c.fetchone()
if result != None:
return result[0]
else: return False
except Exception as e:
#print(str(e))
return False
if __name__ == '__main__':
create_table()
row_counter = 0
paired_rows = 0
with open ('Users/thomasmciver/Desktop/chat/RC_2015-01.txt' buffering=1000) as f:
for row in f:
row_counter += 1
row = json.loads(row)
parent_id = row['parent_id']
body = format_data(row['body'])
created_utc = row['created_utc']
score = row['score']
comment_id = row['name']
subreddit = row['subreddit']
parent_data = find_parent(parent_id)
if __name__ == '__main__':
create_table()
row_counter = 0
paired_rows = 0
# maybe check for a child, if child, is our new score superior? If so, replace. If not...
if score >= 2:
existing_comment_score = find_existing_score(parent_id)
答案 0 :(得分:2)
你是说
with open('Cloud Drive/Desktop/chat/RC_2015-01.txt', buffering=1000) as f:
代替
with open ('Cloud Drive/Desktop/chat/RC_2015-01.txt' (buffering=1000)) as f:
您所拥有的语法无效。