我最近开始学习Python并在这里有一些代码.
...
workout = input("Work out if you won?")
if workout == "y":
ballone()
elif workout == "n":
print("Okay.")
sys.exit("Not working out if you won")
else:
sys.exit("Could not understand")
##Ball one
def ballone():
...
Run Code Online (Sandbox Code Playgroud)
这个问题叫做'ballone'.从命令行(ballone())调用时,您可以看到它已定义并且工作正常
有任何想法吗?我已经在网上搜索,但似乎无法找到任何帮助我的东西.如果有更多的代码需要发布,请告诉我:)
我在获取图像尺寸方面遇到了问题.我想知道图像的宽度和高度,而不是加载到文档中.目前我的代码如下:
function getImageSize (path) {
var image = new Image();
image.name = path;
var d = image.onload = function() {
var w = this.width;
var h = this.height;
return {width : w, height : h};
}();
image.src = path;
return d;
}
Run Code Online (Sandbox Code Playgroud)
如果我调用该函数,我会在两个索引(w,h)中得到包含undefined的对象.我试过不通过排除括号(8行)调用onload处理程序,但我得到的是功能代码.
请注意,如果我alert(w)在onload处理程序体内调用,我可以看到图片的宽度,但不在外面.
有人知道如何解决这个问题吗?我怎样才能获得图像尺寸?