, , -, - (. XY
)
hi bye , . :
class MyGreetings(object):
hello = [1, 2, 3]
def hi(self):
print('hello')
def bye(self):
print(self.hello)
:
global hello
def hi():
global hello
hello = [1,2,3]
print("hello")
def bye():
print(hello)
hi:
def hi():
hello = [1,2,3]
print("hello")
return hello
def bye():
hello = hi()
print(hello)
hi:
def hi():
hello = [1,2,3]
print("hello")
hi.hello = hello
def bye():
hello = hi.hello
print(hello)
, , , , - hi() bye(), hello:
import inspect
from textwrap import dedent
def hi():
hello = [1,2,3]
print("hello")
def bye():
sourcelines = inspect.getsourcelines(hi)[0]
my_locals = {}
exec(dedent(''.join(sourcelines[1:])), globals(), my_locals)
hello = my_locals['hello']
print(hello)