将一个函数嵌入另一个 Jython
embedding one function another Jython
任务的目标是让这两个函数一起工作,或者即让 setPixeltoBlack 被调用到 setPicturetoblack 中。
错误很明显:
The error was:'javainstance' object has no attribute '__call__'
Attribute not found.
You are trying to access a part of the object that doesn't exist.
Please check line 10 of /Users/tobiasdouglas/test3
主要问题:如何要求计算机检查两个变量(xpos、ypos)是否存在?
我写出了所需的伪代码(用#显示)。
谢谢。
import random
file=pickAFile()
picture=makePicture(file)
show(picture)
xpos = input("Enternumber")
ypos = input("Enternumber")
def setPixelToBlack(getPixel):
#if xpos and ypos = known
setColor=(getPixel(picture,xpos,ypos),black)
#else
#setcolor=(getPixels(picture), black)
explore(picture)
return
def setPictureToBlack(picture):
for p in getPixels(picture):
setPixelToBlack(p)
您可以使用特殊值 None
并使用 is None
或 is not None
.
检查变量是否为 None
xpos = None
ypos = None
// some code that may set xpos or ypos
def setPixelToBlack(getPixel):
if xpos is not None and ypos is not None:
setColor=(getPixel(picture,xpos,ypos),black)
// ...
在您的代码中,xpos
和 ypos
也是全局变量。您可以在函数中读取它们,但要更改其值,您需要使用 global xpos, ypos
语句。
任务的目标是让这两个函数一起工作,或者即让 setPixeltoBlack 被调用到 setPicturetoblack 中。
错误很明显:
The error was:'javainstance' object has no attribute '__call__'
Attribute not found.
You are trying to access a part of the object that doesn't exist.
Please check line 10 of /Users/tobiasdouglas/test3
主要问题:如何要求计算机检查两个变量(xpos、ypos)是否存在? 我写出了所需的伪代码(用#显示)。
谢谢。
import random
file=pickAFile()
picture=makePicture(file)
show(picture)
xpos = input("Enternumber")
ypos = input("Enternumber")
def setPixelToBlack(getPixel):
#if xpos and ypos = known
setColor=(getPixel(picture,xpos,ypos),black)
#else
#setcolor=(getPixels(picture), black)
explore(picture)
return
def setPictureToBlack(picture):
for p in getPixels(picture):
setPixelToBlack(p)
您可以使用特殊值 None
并使用 is None
或 is not None
.
None
xpos = None
ypos = None
// some code that may set xpos or ypos
def setPixelToBlack(getPixel):
if xpos is not None and ypos is not None:
setColor=(getPixel(picture,xpos,ypos),black)
// ...
在您的代码中,xpos
和 ypos
也是全局变量。您可以在函数中读取它们,但要更改其值,您需要使用 global xpos, ypos
语句。