Как работает функция 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
#Navoi❗️Trees were cut down at night in Navoi
According to a report we received, the incident took place at night in the Kimyogarlar mahalla of Navoi.
The message states that trees in the area were cut down during nighttime, then loaded onto a truck and taken away. It is also emphasized that the truck allegedly belongs to the Navoi City Department of благоустройство.
An official statement from the responsible authorities is expected. Whether the tree cutting was carried out on legal grounds or not requires clarification.
🌳 The public is calling for transparency and accountability in environmental protection matters.
☘️Read the latest environmental news on the @ekologuz page. Follow us and send your suggestions and wishes via @eklguz_bot
Instagram | Facebook | Twitter | Sayt | Youtube.
Elektron tijorat bo‘yicha amaliy seminar tashkil etildi
🇺🇿Biznes va tadbirkorlik oliy maktabining Navoiy viloyati hududiy filiali hamda xalqaro marketpleys - Wildberries hamkorligida Navoiy shahrida tadbirkorlar, tadbirkorlikka qiziqishi bor aholi va yoshlar uchun “Elektron tijorat sohasida biznesni boshlash va yuritish. Wildberries platformasida savdoni yo‘lga qo‘yish” mavzusida amaliy seminar bo‘lib o‘tdi.
Seminarning asosiy maqsadi hududdagi tadbirkorlar va yoshlarga zamonaviy raqamli savdo platformalari orqali biznes yuritish imkoniyatlarini tushuntirish, ularni elektron tijoratga keng jalb etishdan iborat bo‘ldi.
Ishtirokchilarga marketpleyslarda faoliyat yuritish tartibi, elektron tijoratning huquqiy asoslari, soliq masalalari, logistika jarayonlari hamda talaba yoshlarga marketpleys menejeri kasbini egallash bo‘yicha amaliy tavsiyalar berildi.
Bugungi kunda onlayn savdo platformalari mahalliy ishlab chiqaruvchilar va hunarmandlar uchun nafaqat ichki bozor, balki xalqaro miqyosda ham o‘z mahsulotlarini sotish imkonini yaratmoqda. Bu esa hududiy tadbirkorlikni rivojlantirish, eksport salohiyatini oshirish va yangi ish o‘rinlari yaratishda muhim ahamiyat kasb etadi.
Ishtirokchilar o‘zlarini qiziqtirgan masalalar bo‘yicha mutaxassislardan batafsil javoblar oldilar va platformada ilk qadamlarni boshlash yuzasidan amaliy maslahatlarga ega bo‘ldilar.
Mazkur seminar Navoiy viloyatida elektron tijoratni ommalashtirish, yoshlar va aholining biznes ko‘nikmalarini oshirish hamda raqamli iqtisodiyotni yanada rivojlantirish yo‘lida muhim o‘rin tutadi.
🇷🇺RU
🇬🇧ENG
#GSBE#GraduateSchool#Navoi#Ecommerce#Study
🔝Web-site |🔝Facebook | 🔝Instagram | 🔝Youtube
🇺🇿9-fevral – Buyuk bobokalonimiz Alisher Navoiy tavallud topgan kun!
Bugun biz buyuk shoir va mutafakkir, davlat arbobi va jamoat namoyandasi Alisher Navoiy tavalludining 584 yilligini nishonlanayotgan kun.
✍️ Alisher Navoiy o‘zbek adabiyoti va jahon madaniyatiga bebaho hissa qo‘shgan, o‘z ijodi bilan milliy tilimizning boyligi va go‘zalligini namoyon etgan.
🔖 Uning asarlari ezgulik, adolat va yuksak umuminsoniy qadriyatlarni ulug‘laydi.
📆 Bugun biz buyuk alloma merosini yod etib, uning ijodiy yutuqlaridan ilhom olishda davom etamiz!
#GraduateSchool#Alisher#Navoi#Poet
🔝Web-site |🔝Facebook | 🔝Instagram | 🔝Youtube
🚨 Bukhara poachers… attacked an environmental inspector in Navoi region!
In Navoi Region, in Qiziltepa District, poachers used force against an environmental inspector who attempted to stop them.
According to reports, the following were found in their vehicle:
▪️ 4 firearms;
▪️ illegally hunted hare and ducks.
The individuals were taken by internal affairs officers to clarify the circumstances of the incident and take the necessary legal measures.
❗️ An investigation is currently underway.
#Poaching#Environment#Navoi#LawViolation☘️Read the latest environmental news on the @ekologuz page. Follow us and send your suggestions and wishes via @eklguz_bot
Instagram | Facebook | Twitter | Sayt | Youtube.
#Navoiy
📌 «Assalom, Yangi kun» dasturida suhbat!
⚡️“Hunarmand” uyushmasi Navoiy viloyati boshqarmasi boshlig‘i bilan qiziqarli suhbat bo‘lib o‘tdi.
🎤Suhbat davomida hududdagi hunarmandchilik, yangi loyihalar va hunarmandlar uchun imkoniyatlar haqida so‘z bordi.
📊Hunarmandchilikni rivojlantirish, merosimizni saqlash va yangi avlodga yetkazish — har birimizning vazifamiz!
#Hunarmand#Navoi#AssalomYangiKun#Madaniyat#Rivojlanish
Faсebook|
✅Instagram
✅Youtube |
✅Murojaat yo'llash
🌳 Trees in Navoi Are in Danger!
On Tarobi Street and in other parts of the city, trees are being improperly pruned. Side branches are being cut “haphazardly,” leaving trees looking like palms instead of maintaining their natural shape.
According to research conducted by ecologists, 90% of the cut branches were alive, directly harming the trees and the city’s ecology.
Under the legislation of the Republic of Uzbekistan, particularly the Law “On Environmental Protection” and regulations on the protection of green spaces in urban areas, any work on trees must consider their health and natural form. Although the city administration notes that no special permits are required to trim side branches, this does not exempt anyone from responsibility for damaging trees or violating protection norms.
Ecologists call on authorities and citizens to pay attention to this issue and, if necessary, amend legislation to protect the trees and the city’s green areas.
🌱 Trees are the lungs of our city — we must take care of them!
#Navoi#TreePruning#Ecology#GreenCity#LegalBasis☘️Read the latest environmental news on the @ekologuz page. Follow us and send your suggestions and wishes via @eklguz_bot
Instagram | Facebook | Twitter | Sayt | Youtube.
#Navoi
“Sinovlarda sinmagan” ayol hikoyasi
“Qiyofa” loyihasining navbatdagi mehmoni — Nurotalik ayollarning iftixori, “Shuhrat” medali sohibasi Zarina Hamidova.
Zarina Hamidova o‘zining matonati, mehnatsevarligi va hayot sinovlariga qarshi mustahkam irodasi bilan ko‘pchilikka ibrat bo‘lib kelmoqda.
#Qiyofa#ZarinaHamidova#ShuhratMedali#Nurota#Navoi
Faсebook|
✅Instagram
✅Youtube |
✅Murojaat yo'llash