staticmethod better suited than class method

a classmethod changes the class, i.e. it assigns attributes and gives
them specific values.
a staticmethod does not alter the class

https://www.geeksforgeeks.org/class-method-vs-static-method-python
This commit is contained in:
Martin Diehl 2019-11-26 20:32:54 +01:00
parent 845cfc34ec
commit 925a4f73d6
1 changed files with 3 additions and 3 deletions

View File

@ -239,8 +239,8 @@ class Geom():
header.append('homogenization {}'.format(self.get_homogenization()))
return header
@classmethod
def from_file(cls,fname):
@staticmethod
def from_file(fname):
"""
Reads a geom file.
@ -300,7 +300,7 @@ class Geom():
if not np.any(np.mod(microstructure.flatten(),1) != 0.0): # no float present
microstructure = microstructure.astype('int')
return cls(microstructure.reshape(grid),size,origin,homogenization,comments)
return Geom(microstructure.reshape(grid),size,origin,homogenization,comments)
def to_file(self,fname,pack=None):