简体   繁体   English

Python定义函数错误

[英]Python defining function error

I need to make a function that will post an image in four segments on a canvas using turtle graphics, I have written the following functions 我需要制作一个函数,使用乌龟图形将图像分成四个部分发布在画布上,我编写了以下函数

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

I get this error: 我收到此错误:

NameError: name 'local' is not defined NameError:未定义名称“本地”

How can I make my paste_up function refer to my locations function? 我如何使我的paste_up函数引用我的locations函数?

Assuming paste_up is defined OUTSIDE locations , you call locations(local) here: 假设paste_up在OUTSIDE个locations定义 ,您可以在此处调用locations(local)

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

but of course that local name was never defined. 但是当然,从未定义过local名称。 You'll have to add a parameter or define it (but since you give no info of what that is or where it comes from, that's all I can say) 您必须添加或定义一个参数(但是由于您没有提供任何信息或它来自何处,所以我只能说这些)

Assuming paste_up is actually defined INSIDE locations , your code looks fine and you'll have to give us a traceback that says where the error occurs. 假设paste_up实际上是定义INSIDE locations ,你的代码看起来不错,你得给我们一个回溯,指出其中的错误发生。

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

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