python 2.7 - replacing global variables with class -
hi beginner question here.
i have written script works uses global variables (set input network, , used in different function change state) allow me change , acces content of variables several functions. understand global variables questionable looking replacing them class.
- is idea?
is example of how can done in "correct" way?:
class values1(object):
def __init__(self): self.__height = 2.85 def set_height(self,height): self.__height =height def get_height(self): return self.__height val = values1() def print1(): print (val.get_height()) val.set_height(3.45) def print2(): print val.get_height() print1() print2()
Comments
Post a Comment