Как работает функция reload()?
Эта функция нужна для того, чтобы перезагрузить изменившийся код из py-файла без рестарта интерпретатора.
Дело в том, что любой импортированный модуль при повторном импорте не будет перечитывать файл. Функция импорта вернёт уже загруженный в память объект модуля. Чтобы обновить код, нужно либо перезапустить всю программу, либо использовать функцию reload()
from importlib import reload
reload(my_module)
🔸 Функция reload() принимает в качестве аргумента только объект модуля или пакета. Она не может перезагрузить класс или функцию. Только весь файл целиком!
🔸 Перезагрузка пакета перезагрузит только его файл __init__.py, если он есть. Но не вложенные модули.
🔸Она не может перезагрузить ранее не импортированный модуль.
🔸При вызове функция reload() перечитывает и перекомпилирует код в файле, создавая новые объекты. После создания новых объектов перезаписывается ранее созданный неймспейс этого модуля.
Это значит, что если где-то этот модуль импортирован через import и обращение к атрибутам происходит через неймспейс (имя) модуля, то такие атрибуты обновятся.
Если какие-либо объекты из этого модуля импортированы через from то они будут ссылаться на старые объекты.
Напишем простой модуль
# mymodule.py
x = 1
Теперь импортируем модуль и отдельно переменную х из модуля
>>> import mymodule
>>> from mymodule import x
>>> print(mymodule.x)
1
>>> print(x)
1
Не перезапуская интерпретатор вносим изменения в модуль
# mymodule.py
x = 2
Делаем перезагрузку модуля и проверяем х ещё раз
>>> reload(mymodule)
>>> print(mymodule.x)
2
>>> print(x)
1
То же самое будет если присвоить любой объект переменной (даже словарь или список)
Повторный импорт обновляет значение
>>> from mymodule import x
>>> print(x)
2
🔸Созданные инстансы классов не обновятся после перезагрузки модуля. Их придётся пересоздать.
#tricks#basic
🔥NEW RELEASE🔥
😁Duck Under Masterclass by Cole Abate😁
➡️The Duck Under combines pressure and speed, blending the control of traditional passing with the tempo and sharpness of the modern game, allowing the guard passer to dictate the pace of the fight.
➡️The Masterclass includes more than 5+ hours of entries, concepts, transitions, and submissions. Throughout the 40 classes, Cole demonstrates the effectiveness of the position, and how the Duck Under completely neutralizes the guard player by removing their ability to setup sweeps or submissions.
$̶1̶7̶9̶😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#ColeAbate#GuardPassing#Gi#AOJ
💁♀️Buy
💁♀️
😁Modernized Headquarters Passing By Shawn Melanson😁
➡️Unlock the secrets to one of the most dominant and versatile passing positions in Brazilian Jiu-Jitsu with Modernized Headquarters Passing by Shawn Melanson
➡️As an up-and-coming No-Gi competitor who has conquered tournaments at the highest levels, Shawn brings his proven expertise directly to your training. In this comprehensive instructional series, he breaks down the Headquarters Position, a game-changing technique that can be used against nearly every guard in the sport.
➡️With step-by-step guidance, Shawn reveals how to enter, control, and pass from the Headquarters Position, offering you a wide array of strategic options to dominate your opponent.
$79😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#ShawnMelanson#BJJFanatics#GuardPassing#NoGi#Headquarters
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Things I Didn't Show To Craig Jones: Maintaining An Advantage Over Time - Outside Passing By Jozef Chen😁
➡️Unlock the secrets to unstoppable no-gi guard passing with JPoint Camping, the latest BJJ instructional from one of the most elite no-gi competitors today, Jozef Chen.
➡️In this systematic instructional, Jozef guides you through the step-by-step process of dismantling even the most difficult no-gi guards, using a series of tried-and-true methods refined over years of high-level competition.
➡️Transform your guard passing into a dominant, methodical force, and learn how to effortlessly break through any guard. With Jozef Chen’s expert guidance, you’ll develop the mindset, precision, and fluidity needed to consistently control the pace and flow of your no-gi matches.
$127😍$11.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#JozefChen#CraigJones#CJI#GuardPassing
💁♀️Buy
💁♀️