Как работает функция 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
Let’s bring the Dogs Data to TikTok
Join the 🐾 TikTok community
Like and share our videos their whenever you can
https://www.tiktok.com/@kennel.ai?_t=8h0SUOsjUHI
#DogData #$DOGS #Web3#DogBreeder#DogNFT
Let’s bring the Dogs Data to TikTok
Join the 🐾 TikTok community
Like and share our videos their whenever you can
https://www.tiktok.com/@kennel.ai?_t=8h0SUOsjUHI
#DogData #$DOGS #Web3#DogBreeder#DogNFT
The kennel.ai core team and team of DogShow influencers can be contacted easily through Telegram, Twitter, YouTube etc or directly by email at [email protected]
Feel free to offer marketing and promotional services
Admin @NEO55555
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
The Kennel.Ai ecosystem has a stabil Token
https://kennel.ai/tokenomics
…use of KC stabil Token is for making either donations to street dog feeding campaign
https://kennel.ai/to-earn
or
for buying products ( on chain ) from the Webshop using crypto
https://kennel.ai/shop
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
Happy December 01 🐶🦴
The kennel.ai core team and team of DogShow influencers can be contacted easily through Telegram, Twitter, YouTube etc or directly by email at [email protected]
Feel free to offer marketing and promotional services
Admin @NEO55555
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
One of the core features of the Kennel.ai ecosystem is charitable donations to community that give their waste table food to street dogs
https://kennel.ai/to-earn
Millions of dog lovers worldwide care about the plight of abandoned street dogs
…that’s why Team have created the offer of being the middle man for European and American dog lovers that like to donate money to sponsor the feeding of street dogs in places like India , Romania and other countries where the street dogs need help…
at least join the platform today to show your support for this campaign 🐾
https://kennel.ai/login
Have a great day ….
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
The Pet dog Industry problem is that the data collected is held on hundreds of independent servers Worldwide
25 million new pet dogs are registered with the worlds fragmented kennel clubs each year
This is a multi billion dollar industry, the average price for a pet dog now in 2023 Europe and USA is $1000-1500$
In the Future every Pet dog will be physical digital asset , data on chain
Kennel.Ai creates a unique editable NFT for each new pet dog registered
You can join the Kennel.Ai ecosystems and help tobtest the platform by registering a dog, start to earn tokens for the data provided by you and supplemental tokens for the data provided by owners of any offspring produced by your dog
https://kennel.ai/login
Kennel.Ai aims to provide one place on chain for all the worlds kennel clubs members, breeders and pet dog owners to record and own their dog life data…
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
One of the core features of the Kennel.ai ecosystem is charitable donations to community that give their waste table food to street dogs
https://kennel.ai/to-earn
Millions of dog lovers worldwide care about the plight of abandoned street dogs
…that’s why Team have created the offer of being the middle man for European and American dog lovers that like to donate money to sponsor the feeding of street dogs in places like India , Romania and other countries where the street dogs need help…
at least join the platform today to show your support for this campaign 🐾
https://kennel.ai/login
Have a great day ….
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
The kennel.ai core team and team of DogShow influencers can be contacted easily through Telegram, Twitter, YouTube etc or directly by email at [email protected]
Feel free to offer marketing and promotional services
Admin @NEO55555
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
The kennel.ai core team and team of DogShow influencers can be contacted easily through Telegram, Twitter, YouTube etc or directly by email at [email protected]
Feel free to offer marketing and promotional services
Admin @NEO55555
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
One of the core features of the Kennel.ai ecosystem is charitable donations to community that give their waste table food to street dogs
https://kennel.ai/to-earn
Millions of dog lovers worldwide care about the plight of abandoned street dogs
…that’s why Team have created the offer of being the middle man for European and American dog lovers that like to donate money to sponsor the feeding of street dogs in places like India , Romania and other countries where the street dogs need help…
at least join the platform today to show your support for this campaign 🐾
https://kennel.ai/login
Have a great day ….
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
In our busy lives reminders are essential
How about reminders for when your pet dogs vaccinations are due for boost
Kennel.ai records dog life data on chain such as vaccination type and expiry date
Platform reminds pet dog owners when either a vaccination or booster is needed via mobile and by a notification when user is logged in to platform with Google or Web3 metamask
https://kennel.ai/login
Kennel.Ai aims to provide one place on chain for all the worlds kennel clubs members, breeders and pet dog owners to record and own their dog life data…
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai