繁体   English   中英

Python定义函数错误

[英]Python defining function error

我需要制作一个函数,使用乌龟图形将图像分成四个部分发布在画布上,我编写了以下函数

def locations(local):
# Move to location
    if local[1] =='Location 1':
        goto(-300,0)

    elif local[1] == "Location 2":
        goto(-150,0)

    elif local[1] == 'Location 3':
        goto(0,0)

    elif local[1] == "Location 4":
        goto(150,0)

# Get correct Orientation
    if local [2] == "Upright":
        setheading(0)
    elif local [2] == "Upside down":
        setheading(180)


def paste_up (arrangement):
    for sheets in arrangement:
        if (len(sheets)>1):
            print(sheets[1])
            for places in "Data_sets":
            if sheets [0] == 'Sheet A':
                locations(local)
                sheeta()
            elif sheets [0] == "Sheet B":
                sheetb()
            elif sheets [0] == 'Sheet C':
                sheetc()
            elif sheets [0] == 'Sheet D':
                sheetd()

我收到此错误:

NameError:未定义名称“本地”

我如何使我的paste_up函数引用我的locations函数?

假设paste_up在OUTSIDE个locations定义 ,您可以在此处调用locations(local)

if sheets [0] == 'Sheet A':
    locations(local)

但是当然,从未定义过local名称。 您必须添加或定义一个参数(但是由于您没有提供任何信息或它来自何处,所以我只能说这些)

假设paste_up实际上是定义INSIDE locations ,你的代码看起来不错,你得给我们一个回溯,指出其中的错误发生。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM