嵌入一​​个函数另一个Jython

时间:2015-01-12 19:22:10

标签: function 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)? 我写了pseduocode(用#表示)所需的内容。

感谢。

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)

1 个答案:

答案 0 :(得分:0)

您可以使用特定值None并使用Noneis None检查变量是is not 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)
    // ...

同样在您的代码中xposypos是全局变量。您可以在函数中读取它们,但要更改其值,您需要使用global xpos, ypos语句。