Как работает функция 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
🚀 THE GUCARD CHAMPIONS’ LEAGUE BEGINS! 🔼
GuCard is officially LIVE for our first whitelist users! 🎉 Congratulations to those who are among the first to experience the future of payments!
Now it’s time to show the world how GuCard works in real life! 🌍💵
🎥 How to Join:
1️⃣Create a video showcasing how you use your GuCard in everyday transactions.
2️⃣ Post it on X and tag @Gumart__.
3️⃣ Use #GuCard to spread the word!
🏆 BIG PRIZES (Top 3 Winners): $5,000in total (loaded directly onto your GuCard!)
🗓Contest period:Feb 16 – Feb 28
Be creative, be bold, and let’s show the world the power of GuCard! 💳
📦 GUCARD CHAMPIONSHIP EXTENDED – MORE TIME, MORE REWARDS! ⚡️
Due to the incredible response, we’re extending the GuCard Champions League until March 22! ✨
That means more chances to win BIG while showcasing how you use GuCard in real life!
🎥 How to Join:
1️⃣ Create a video showing how you use your GuCard for everyday payments.
2️⃣ Post it on X and tag @Gumart_Official.
3️⃣ Use #GuCard to spread the word!
🏆 BIG PRIZES – NOW EXTENDED!
💰 Top 3 Winners: $5,000 in total (loaded directly onto your GuCard!)
🗓 New Deadline: March 22
More time, more winners, and even more ways to showcase GuCard’s power! 💳
#GuMinigame
✨🥳 GUCARD CREATIVE CONTEST IS HERE! 🥳✨
Are you ready to show off your creativity and love for Gumart? 💸 Join the Gucard Creative Contest and turn your ideas into amazing content! 🎥🖌
👍 How to Join:
1️⃣ Create unique content (video, photo, meme, or text) featuring Gucard or Gumart.
2️⃣ Post it on X or YouTube with the hashtag #Gucard#Gumart
🏆Prizes Await You:
🎖Main Prizes:
1st Place: 1,000 USDT (1 winner)
2nd Place: $500 USDT (3 winners)
3rd Place: $50 USDT (5 winners)
🌟 Community Choice Awards:
50 winners: $10 each (based on community engagement).
💳 Special Bonus: All winners will receive a free Gucard!
🗓Timeline:
🕐 Start: January 5, 2025
⏳ End: January 19, 2025
🔥 Criteria for Winning: Creativity, quality, and interaction - bring your A-game!
#GuMinigame
🥉 GuCard Champions' League – Third Place Revealed!🛍
After NYC and Korea, we now head to the Philippines!
Big congratulations to @mkddavidson, our 3rd Place Winner, who showed how easy it is to grab snacks at the supermarket or order McDonald’s - all using GuCard and GTP. 👍
You’ve won 1,000 USDT, already loaded to your GuCard!
🎥 Watch the winning video: link
GuCard is going global - and this is just the beginning!✋
#GuMinigame#GuPay#GuGoGlobal#GuCard