给定一个带有辅助方法进行初始化的类:
class TrivialClass:
def __init__(self, str_arg: str):
self.string_attribute = str_arg
@classmethod
def from_int(cls, int_arg: int) -> ?:
str_arg = str(int_arg)
return cls(str_arg)
Run Code Online (Sandbox Code Playgroud)
是否可以注释方法的返回类型from_int?
我试过两个cls,TrivialClass但是PyCharm将它们标记为未解决的引用,这在那个时间点听起来很合理.
我试图在Sphinx中使用autodoc打印出特定模块中每个函数的文档字符串,但不包括模块的文档字符串。可能吗?
原因是我使用模块docstring指定命令行选项(带有可爱的docopt)。
我正在开发一个iPad项目,我试图通过切换预渲染图像来模拟3D体的旋转.
在内存管理方面,我不是最敏锐的人,所以我想知道是否有人有关于如何优化这一点的任何提示.
我的解决方案现在看起来像这样:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [[event allTouches] anyObject];
CGPoint location = [myTouch locationInView:self.view];
int pictureIndex;
//Rough mapping of image to point on screen
if (location.x <= 384 ) {
pictureIndex = (384 - location.x)/(768/rotatingPictures)+1;
}
else {
pictureIndex = rotatingPictures - (location.x-384)/(768/rotatingPictures)+1;
}
[theImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"image_%d.png", pictureIndex]]];
Run Code Online (Sandbox Code Playgroud)
}
以这种方式加载图像是否有效?将图像首先加载到数组或类似的东西会更好吗?
我希望一次加载所有加载时间而不是旋转时加载.