Код: Выделить всё
barry = "Hello"
Код: Выделить всё
from vars import barry
def init():
global barry
print (f'old barry = {barry}')
barry = 'terminal'
print (f'New barry = {barry}')
Код: Выделить всё
#!/usr/bin/env python3
from vars import barry
from init import init
print (f'In Main, barry = {barry}')
init()
print (f'In Main, after init , barry = {barry}')
Код: Выделить всё
In Main, barry = Hello
old barry = Hello
New barry = terminal
In Main, after init , barry = terminal
< /code>
Вместо этого я получаю: < /p>
In Main, barry = Hello
old barry = Hello
New barry = terminal
In Main, after init , barry = Hello
кажется, что Barry остается локальным в INIT.PY вместо того, чтобы менять глобально.
Подробнее здесь: https://stackoverflow.com/questions/794 ... n-using-gl