TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #205 · 22 јан.

Как работает функция 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

Резултати

Пронајдени 1 слични објави

Пребарај: #tontix

当前筛选 #tontix清除筛选

🍿 TONTIX: $TNT presale is coming! TONTIX announced that very soon, a presale of $TNT tokenswill be conducted! This is a unique opportunity to become a part of this exciting project and support the development of a platform that will revolutionize ticket sales. 📊According to TNT tokenomics, 7% of the total token allocation will be dedicated to the presale. Buying the$TNT means gaining numerous benefits and investing in the future development of our project. The funds raised during this presale will be used to enhance the platform, expand our team, and advance our marketing efforts to reach a wider audience. 🎫Benefits of holding $TNT tokens: 🔵Exclusive Access: Token holders will have priority access to special events, promotions, and unique experiences. 🔵Voting Rights: Participate in the governance of TONTIX by voting on key decisions that shape the platform’s future. 🔵Rewards and Incentives: Earn rewards for your participation and engagement within the TONTIX ecosystem. 🔵Discounted Fees: Enjoy reduced service fees when purchasing tickets through the TONTIX dApp. 🔵Investment Potential: As the TONTIX platform grows, so too may the value of your tokens, offering potential for appreciation. Your participation will help the team to achieve this goal and shape the future of the ticketing industry. So don't miss the opportunity to join the project from the very beginning! Details about the date and terms of the presale will be announced very soon, so stay tuned for updates! 💙 Right now you can get 50 $wTNT as a reward for joining!✨ Chat | Website | Channel | Demo #tontix#presale#ticket#web3#NFT