I have a code which has few Classes in it. Under SecondClass
, there is a function called plot_image
. Under this function, there are three variables defined called my_x, my_y, my_z. I am trying to make these variables accessible inside some other function called get_histogram
in the same Class. Here is a non-working example in the form of a pseudo-snippet:
import some_modules_in_here #these are required for classes below
#===================================================================================================
# utility
#===================================================================================================
class FirstClass(something.something.SayClass):
def file1(self, some_arguments):
pros = do_something
return pros
#===================================================================================================
# visualize
#===================================================================================================
class SecondClass(something.something.SayClass):
def plot_image(self, some_parameter):
if some_parameter is not None:
my_x = some_value1
my_y = some_value2
my_z = some_value3
def get_histogram(self, some_parameter, some_other_parameter, return_info):
if '3d' in some_parameter:
do_this
else:
do_that
if some_other_parameter:
calculate_something
if return_info:
for k, l, m in zip(my_x, my_y, my_z):
do_some_stuff
print(something_in_here)
return_value = do_something_else_in_here
return return_value
.
.
.
def print_values(self):
'''
write some values of image to file.
'''
Second = SecondClass()
I tried the keyword global
at the top of the function plot_image
but that doesn't do the job for me giving error message:
"NameError: Name 'my_x' is not defined."
What is the solution?