Как работает функция 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🔥
😁Systematically Attacking The Half Guard and Scrimmaging: Whizzer vs Underhook by Gordon Ryan😁
➡️In Systematically Attacking The Half Guard and Scrimmaging: Whizzer vs Underhook, Gordon Ryan breaks down one of the most common—and misunderstood—positions in all of Jiu-Jitsu, and turns it into a clear, repeatable system you can rely on every time.
➡️Widely regarded as the most accomplished No-Gi grappler of all time, Gordon is known for his unmatched submission rate and his ability to teach complex positions with precision and clarity. This series is a perfect example of that.
$349😍$24.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#GordonRyan#Sweeps#NoGi#NewWave
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Knee Lever Masterclass by Brian Glick😁
➡️The Knee Lever Masterclass from Brian Glick, a John Danaher black belt and one of BJJ Fanatics’ best-selling instructors, is your complete system for turning one of Jiu-Jitsu’s most underrated techniques into a powerful, all-position weapon
➡️Known for his world-class instruction, clear communication, and simple, effective systems, Brian once again delivers an instructional packed with precise details and universal concepts that make complex ideas easy to apply.
$197😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#BrianGlick#Sweeps#NoGi#NewWave
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Master The Move: The Butterfly Guard Sweep Sumi Gaeshi by John Danaher😁
➡️In Master The Move: The Butterfly Guard Sweep Sumi Gaeshi, Danaher breaks down what many consider the single most effective sweep in grappling.
➡️Now, for the first time, Danaher reveals the complete system behind the Sumi Gaeshi sweep from butterfly guard — the same position that connects effortlessly to leg locks, back takes, and devastating top control sequences.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#JohnDanaher#Sweeps#NoGi#NewWave
💁♀️Buy
💁♀️
😁Top 10 Sweeps and Reversals by Magid Hage😁
➡️In Top 10 Sweeps and Reversals, Magid Hage breaks down the most basic, high-percentage sweeping techniques that every Brazilian Jiu-Jitsu practitioner should have in their game.
➡️This course focuses on simplicity, timing, and efficiency, showing you how to off-balance your opponent and reverse the position with minimal strength and maximum control.
$79😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#MagidHage#Sweeps#NoGi#IBJJF
💁♀️Buy
💁♀️
😁Precision Sweeps And Wrestle Ups From The Seated Position By Shawn Melanson😁
➡️Master the art of disrupting standing passers with surgical precision. In his fourth and most dynamic instructional to date, best-selling BJJ coach Shawn Melanson delivers a comprehensive system for attacking from the seated guard — blending positional off-balancing, precision timing, and relentless wrestle-ups to systematically frustrate and dismantle your opponent’s passing game.
➡️Shut down standing passers with precision sweeps, wrestle-ups, and off-balancing tactics from seated guard in Shawn Melanson’s latest high-level BJJ instructional.
$79😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#ShawnMelanson#Sweeps#NoGi#WrestleUp
💁♀️Buy
💁♀️