Как работает функция 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
⚡️Gatto Official Channel: PvP Event with Rewards
#GTON#PvP
Join the Gatto Official Channel for an exciting PvP event and fight against the GTeam from 15:00 UTC today. Players can earn special rewards by achieving consecutive wins against the GTeam, with the event running until May 30. European server only.
Source: link
@tonlines
MRKT: New Winter League Begins
#MRKT#PVP
The MRKT channel announces the start of the Winter Open League, bringing new competitions and rewards after the completion of the Autumn season. Players can look forward to fresh rankings, new rivals, and exclusive prizes including the Heart Locket and Durov’s Cap.
Source: link
@tonlines
⚡️MRKT: Important Update on PVP Competition Rules
#MRKT#PVP
MRKT announces a new rule to ensure fair competition in PVP leaderboards. Contributions exceeding 92% of a game's pool will not influence tournament rankings. Participants are encouraged to play fairly.
Source: link
@tonlines
MRKT: New Feature Enhances PvP Experience
#MRKT#PvP
MRKT introduces PvP Reactions, allowing players to drop reactions during fights to enhance excitement and energy in battles. This feature aims to change the atmosphere of the arena.
Source: link
@tonlines
MRKT Enforces Fair Play in PvP Events
#MRKT#PvP
MRKT emphasizes fair play in all PvP events, actively monitoring for suspicious activities like volume boosting and artificial staking. Participants found engaging in abuse or manipulation risk being banned without explanation.
Source: link
@tonlines
⚡️MRKT: Last Hours of PvP Tournament Finale
#PvP#Tournament
The MRKT channel announces that there are only 9 hours left in the Autumn Open League PvP Tournament. Participants still have the chance to improve their standings with every fight, stake, and point.
Source: link
@tonlines
⚡️Gatto Official Channel: Weekend Tournament Rescheduled
#tournament#PvP
The Gatto Official Channel has announced the cancellation of the weekend tournament due to technical improvements in PvP mode. The event has been rescheduled to April 25, with double rewards offered for skipping. More details will be provided on the event day.
Source: link
@tonlines
⚔️FOMO Fighters Player Database is Live!
Looking for opponents for PvP battles in 🔥Fomo Fighters ?
Now it's easier than ever.
I’ve created ⚡Fomo Tools — a app that collects the entire player database in one place so you can quickly search and find fighters.
⚔️What you can do:
🟢Find any player instantly
🟢Search fighters for PvP battles
🟢Explore the growing Fomo Fighters community
No more endless scrolling or guessing usernames — just search and battle ⚔️
Try it here:
📣 @FomoTools
If you enjoy the tool, feel free to share it with other fighters and make the PvP scene even more active!
#fomo#fighters#FomoFighters#PvP#tools
Gatto Official Channel: Celebrating Two Years of Growth
#Gatto#PvP#BattlePass
Gatto Official Channel marks its second anniversary with numerous updates and improvements. Over the past year, the game has expanded its offerings with new PvP mechanics, a Battle Pass, and additional content, enriching the player's experience. As the community celebrates, special events and items are available, leading up to upcoming giveaways.
Source: link
@tonlines
✅Nueva actualización del juego Solitario de THNDRGAMES.
⚒️ Ahora están disponibles los duelos PvP y por supuesto el que gane va a ganar satoshis
👉Más info aquí:
https://www.thndr.games/post/duels
✅Actualice la app si ya la tiene, sinó descarga los juegos aquí: ⚡THNDRGAMES
#pvp#p2e#btcln#freebtc