Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
a = "1" def f(): global a a = "2" print(a)
def new_name(): a() with open("test.txt", "a") as myfile: myfile.write("import time \nfrom main import urli \nprint(urli) \ntime.sleep(2)") file_oldname = os.path.join("test.txt") file_newname_newfile = os.path.join("name.py") try: os.rename(file_oldname, file_newname_newfile) except FileExistsError: os.remove("name.py") try: os.remove("test.txt") except FileNotFoundError: pass new_name() os.system("name.py") def a(): global urli urli = "2"
import time from main import urli print(urli) time.sleep(2)
import time print(2) time.sleep(2)
import os import sys def new_name(): a() with open("test.txt", "a") as myfile: myfile.write("import time \nfrom main import urli \nprint(urli) \ntime.sleep(2)") file_oldname = os.path.join("test.txt") file_newname_newfile = os.path.join("name.py") try: os.rename(file_oldname, file_newname_newfile) except FileExistsError: os.remove("name.py") try: os.remove("test.txt") except FileNotFoundError: pass new_name() os.system("name.py") def a(): global urli urli = "2" new_name() urli
a = "1" def f(): global a a = "2" f() print(a)