Как работает функция 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
GM OneEarth community, it's been a while! 🎆
Venue:X Space
Special Guest:@MissWRosa@woxiangni1997
🗓 May 15th 10 PM UTC+9
💰$100 #Giveaways👇
1️⃣Join the Bot :OneEarth Bot
2️⃣ Ask questions in Comment
3️⃣ Like & RT
Remember: One Earth, One Community! 🌎⚡️
✨ Giveaway: Creative Ways to Hide Your Tangem Wallet
🥳Our Discord Community Turns 1!
Celebrate with us by showing off your creativity in our special anniversary giveaway!
Are you a master of concealment? We’re challenging you to come up with the most fun hiding places for your Tangem Wallet. Whether it’s hidden in a book on your shelf or tucked behind a secret panel, we want to hear your best ideas!
🏆 5 Tangem branded Hoodies to be won on Discord in the #giveaways channel
👀 How to Enter:
Share your creative hiding spots in the #giveaways thread → top ideas, as voted by our community members, will win.
📅 Dates: Enter until the 28th June → 1st July we do a community vote → then we share the winners!
Cheers to the next year of the Tangem Community - to health, stealth, and wealth!
👾Join Discord and take part in contest →https://discord.com/invite/tangem
📰You can make your payment via @Premiumbot or Fragment to activate Giveaways
Currently, because this service is not ready, you'll receive ACCESS_DENIED message from the bot.
#Giveaways
👉The TG Times
📰Win Telegram Premium
By having all the conditions to receive Telegram Premium Gift from the channels, among the participants in this Giveaway, the desired number will be randomly selected to receive this gift.
After winning, a message containing the link to activate this subscription will be sent to you via Telegram.
You can also share this link with your friends so that they can get this subscription.
#Giveaways
👉The TG Times
📰New options for Giveaways
You can enable Additional Prizes if you want to give the winners your own prizes in addition to Premium subscription.
Also you can choose whether to make the list of winners public when the Giveaway ends.
#Giveaways | #Beta v.10.4
👉The TG Times
📰Giveaway Prizes
Giveaway Premium subscriptions to your channel members
Telegram is launching a new system to upgrade channels, where channel admins can create Premium Giveaways and set conditions such as location and date for them and boost their channels in this way.
This system is not yet fully available and can only be accessed on the test server.
Giveaway sources: @betawatch
#Giveaways | #Beta v.10.2
👉The TG Times
📰Giveaways are getting ready to be activated on the main server
Telegram beta configuration updates in each version make the Giveaways more complete and prepare for official presentation.
This system was active for some to receive more boosts from the first release of the beta version 10.2.0 on the test server.
Also, multiple boosts and the possibility of boosting more by giving a Premium gift are not activated on the main server, which can be related to the Giveaways.
It is expected that this system will be launched soon in the next updates for the main server.
Configurations by @tgcrawl
#Giveaways | #Configuration
👉The TG Times
Tonnel Network: New Measures Against Bot Farms in Giveaways
#giveaways#restrictions
Tonnel Network has enhanced measures to combat bot farms that manage to bypass restrictions in giveaways. Channel owners are encouraged to set at least one restriction to ensure the integrity of their free giveaways.
Source: link
@tonlines