Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

syntax error when taking input in python?

I'm new to python. Could anyone suggest what goes wrong with this input command. I'm running this code in python 3.7.0 from anaconda

def annotation_tool(path):
final_results = []
nlp = spacy.load("en_core_web_sm")
if path != '':
    file_text = open(path, "r").read()
    nlp_file_doc = nlp(file_text)
    sentences = list(nlp_file_doc.sents)
    for i in sentences:
        print("--------- Next sentence is %s ---------".format(i))
        print("--------- Possible candidates are %s ---------".format(apply_extraction(row,nlp))
        num_candidates = int(input("Enter number of candidates"))
        pair = []
        for x in range(0, num_candidates):
            candidates = input("--------- Enter candidates e.g. computer, good ---------")
            polarity = input("--------- Enter polarity of above candidates (pos/neg/neu) ---------")
            dict = {candidates: polarity}
            pair.append(dict)
        result = {"sentence": i, "candidates": pair}
        final_results.append(result)
        is_continue = input("--------- Continue with annotation y/n? ---------")
        if is_continue == 'n':
            break
return final_results

Here is syntax error:

File "test.py", line 128
num_candidates = int(input("Enter number of 
candidates"))
SyntaxError: invalid syntax

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The error is from the line above:

print("--------- Possible candidates are %s ---------".format(apply_extraction(row,nlp))

missing a closing parenthesis on the print statement

print("--------- Possible candidates are %s ---------".format(apply_extraction(row,nlp)))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...