我正在开发2.7.3python。我用Layer
类创建了一个脚本,其中有Sublayer
类。我修改了后者的__str__
方法,但它不接受修改。你知道吗
代码:
#-*- coding: utf-8 -*-
import numpy as np
class Layer:
class Sublayer:
def __init__(self, mask, surface, height):
self.mask = mask
self.surface = surface
self.height = height
def __str__(self):
print '\n ---- Couche ---- \n ----------------\n'
cc = " Surface de la couche : "
cc += str(self.surface) + "\n Hauteur : "
cc += str(self.height) + '\n'
return cc
def __getitem__(self):
return (self.mask, self.surface, self.height)
然后我创建了另一个脚本,tests脚本:
import numpy as np
from ClassLayer import Layer
l5 = np.array([[0,0,0,0,0,0, 0,0,0,0],
[0,0,0,0,0,0, 0,0,0,0],
[0,0,0,0,0,0, 0,0,0,0],
[0,0,0,0,0,0, 0,0,0,0],
[0,0,0,0,0,150,0,0,0,0],
[0,0,0,0,0,0, 0,0,0,0],
[0,0,0,0,0,0, 0,0,0,0],
[0,0,0,0,0,0, 0,0,0,0],
[0,0,0,0,0,0, 0,0,0,0],
[0,0,0,0,0,0, 0,0,0,0]])
h5 = np.max([np.max(l5[i]) for i in range(len(l5))])
if h5 != 1:
s5 = sum(sum(l5))/h5
che5 = Layer.Sublayer(l5,s5,h5)
print che5
因此,在执行打印时,它不会考虑我在Sublayer
的__str__
中添加的新修改。你知道吗
如果可能的话,我如何编写这段代码,使两个脚本保持分离?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐