gpt4 book ai didi

python - 全局找不到名称代码错误

转载 作者:太空宇宙 更新时间:2023-11-04 06:09:46 24 4
gpt4 key购买 nike

def choose():
file = pickAFile()
pic = makePicture(file)
return pic

def negative(pic):
for p in getPixels(pic):
setRed(p, 255 - getRed(p))
setGreen(p, 255 - getGreen(p))
setBlue(p, 255 - getBlue(p))
explore(pic)

def main():
choose()
negative(pic)

我收到这个错误:

The error was:pic Name not found globally. A local or global name could not be found. You need to define the function or variable before you try to use it in any way. Please check line 15 of C:\Users\nh_2109\Desktop\s

求助?:D

最佳答案

您还没有在 main 方法中定义 pic

def main():
pic = choose()
negative(pic)

可能是您想要的,因为 choose() 返回一个 Pic 类的实例。

关于python - 全局找不到名称代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19568703/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com