是什么导致 return() 产生 SyntaxError?

What causes this return() to create a SyntaxError?

我需要这个程序创建一个 sheet 作为 ' ' 字符的字符串列表并将文本字符串(来自列表)分配到其中。我已经在 python 3 中编写了 return 语句,但是这个语句一直在

return(riplns)
     ^
SyntaxError: invalid syntax

它是第 39 行的 return(riplns)。我希望该函数在围绕另一个 randint 构建的范围内创建一些随机数 (randint),来自调用的函数 ripimg()这个。

我清楚地看到程序在哪里声明了我希望 return() 给我的列表。我知道它的类型。我看到我在哪里通过 .append() 向它提供变量(int 类型)。我从互联网研究中了解到 python 的 return() 函数的语法错误通常来自错误输入,但似乎并非如此。

#loads the asciified image ("/home/userX/Documents/Programmazione/Python projects/imgascii/myascify/ascimg4")
#creates a sheet "foglio1", same number of lines as the asciified image, and distributes text on it on a randomised line

#create the sheet foglio1
def create():
    ref = open("/home/userX/Documents/Programmazione/Python projects/imgascii/myascify/ascimg4")
    charcount = ""
    field = []
    for line in ref:
        for c in line:
            if c != '\n':
                charcount += ' '
            if c == '\n':
                charcount += '*' #<--- YOU GONNA NEED TO MAKE THIS A SPACE IN A FOLLOWING FUNCTION IN THE WRITER.PY PROGRAM
                for i in range(50):#<------- VALUE ADJUSTMENT FROM WRITER.PY GOES HERE(default : 50):
                    charcount += ' '
                charcount += '\n'
        break
    for line in ref:
        field.append(charcount)
    return(field)

#turn text in a list of lines and trasforms the lines in a list of strings 

def poemln():
    txt = open("/home/gcg/Documents/Programmazione/Python projects/imgascii/writer/poem")
    arrays = []
    for line in txt:
        arrays.append(line)
    txt.close()
    return(arrays)

#rander is to be called in ripimg()
def rander(rando, fldepth):
    riplns = [] 
    for i in range(fldepth):
        riplns.append(randint((rando)-1,(rando)+1)
    return(riplns) #<---- THIS RETURN GIVES SyntaxError upon execution

#opens a rip on the side of the image.
def ripimg():
    upmost = randint(160, 168)
    positions = []
    fldepth = 52 #<-----value is manually input as in DISTRIB function.
    positions = rander(upmost,fldepth)
    return(positions)


剩下的程序我省略了,相信这些功能已经够明白了,如果还需要补充请告诉我。

您的上一行括号不完整。

这一行:-

riplns.append(randint((rando)-1,(rando)+1)

最后还得加一个大括号。这是导致错误的原因,因为 python 一直在阅读内容,并认为 return 语句是前一个未完成行的一部分。