Assume that I have a class ClassName
which contains a method Met
inside its body. Also there is a global variable var
that is needed in Met
.
var=1
class ClassName():
def __init__(self):
# ...
#some other methods that do not need global variable here
def Met():
#do some other stuff that needs the global var
Which (if any) of the forms below are correct/better?
""" Approach one """
var=1
class ClassName():
def __init__(self):
# ...
#some other methods that do not need global variable here
def Met():
# needs the global var to operate
global var
# do some stuff with var (including editing)
""" Approach two"""
var=1
class ClassName(var):
def __init__(self):
# ...
#some methods that do not need global variable here
def Met(var):
# do some stuff with var (including editing)
PS
I have updated my question. Now my question concerns the class and method instead of functions within a function (which is not common nor recommanded).