There are similar questions on stack overflow, but I am not doing wrong in my code. When I use the Is this because newPic has not been saved? How can I save changes in the new PIC? This when you Define the function (here Python interpreter code reads in sequence (sequentially). As the Note: Here, I have used 2 variables equally, which evenly call Thus the above code is equivalent to this one: Edit: Using one of the options, Note that mango Speaking on the contrary, try to avoid using a global variable is always better designs, especially with Python, which is clearly object-oriented ... I hope that I have made myself clear, if not, then the obvious Do not hesitate to ask hereof. search (newPic) or
show (newPic) function outside I do, then gives a blank white canvas.
area variable:
copyPic () ) All the variables created inside this function are "visible" only by the function Global program does not know anything about its existence
newPic is defined in the first position in the function, it is its and it is deleted after the function is finished. This is the reason why you can not mention
newPic after this. You'll need to return the variable (keyword
return ) to fix this, so you can call it
copyPic () function while calling the main program. P> You must do the following:
def copyPic (): file = pickAFile () oldPic = makePicture (file) newPic = makeEmptyPicture (getWidth ( Y category (0, getHeight): range for x (0, gatewidth (old pic)): old pixel = matching pixels (old, x, y) color = milling (for oldPic), getHeight (oldPic) (Old pixel) newPixel = getPixel (newPic, y, x) SetColor (newPixel, color) returns newPic # Here is the important thing newPic = copyPic () # We allocate the return value here to a new variable # Ray "related. Exposure (nepic)
newPic Are there. Geothon is interpreted as the two different variables by the interpreter:
global scope)
def copyPic (): File = PickAFile () ... Return newPic newPic_2 = copyPic () # Here we return "newPic" by another # variable function to "newPic_2" (which is # a "global variable") Es. Explore (newPic_2)
global keywords to do all this, will tell the interpreter that
newPic can be found from the global faculty:
< Code> newPic = None # First declare "Nuperk" at the world Def copyPic (): Tell the function to refer to Global Nupique # Global Variable. ... # Return Nuphak # No need to return anything; Function # Modifies the correct variable CopyPic () Explore (nuepic)
No comments:
Post a Comment