Как работает функция 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
News: #UK bans all travels to #Tigray, #Amhara, and #Gambela regions, issues sweeping warnings across Ethiopia
The British government has significantly expanded its travel warnings for #Ethiopia, banning all travels to Tigray, Amhara and Gambella regions and advising against travels to several regions and large border areas owing to deteriorating security conditions.
In its latest advisory, the UK Foreign, Commonwealth & Development Office (#FCDO) stated:
UK nationals are advised against all travel to Tigray region, where recent reports show militarized tensions in various places.
UK’s travel warning also bans all travels to Amhara region, where a war between government and the Fano armed groups remained active since it first broke in 2023; and Gambela region, where renewed clashes saw scored killed and schools shuttered.
The advisory also extends to all areas within 10 kilometers of Ethiopia’s border with #Eritrea, and within 20 kilometers of the ….
Read more: https://addisstandard.com/?p=54877
News: #Australia issues ‘do not travel’ advisory for #Tigray, #Amhara, and other regions in #Ethiopia
The Australian government has issued a “do not travel” advisory for Ethiopia’s Tigray regional state, warning that the security situation could deteriorate rapidly with little or no warning, according to its latest update on the Smartraveller travel advisory platform.
In the update, Australian authorities urged their citizens currently in Tigray to leave when it is safe to do so using commercial means, noting that Australia’s ability to provide consular assistance in the region remains “extremely limited.” Travelers were also advised to follow local authorities’ instructions and to shelter indoors in the event of civil unrest or armed conflict.
Beyond Tigray, Australia continues to advise against all travel to the Amhara, #Benishangul-Gumuz, and #Gambela regional states, as well as border areas with #Eritrea, #Sudan, #South_Sudan, #Kenya, and #Somalia,....
Read more: https://addisstandard.com/?p=54924
Area Sales Manager
#ethiochicken_ethiopia
#business
#Bule | #Ambo | #Gambela | #Ginir | #Hosaena | #Yirgachefe | #Sheno
BSc Degree in Animal Science, Veterinary field of study
Duties & Responsibilities:
- Develop specific plans to ensure sales growth agent appointment in the territory
- Map how to achieve sales volume through prioritizing to make big achievement with minimum effort and shorter time
Quanitity Required: 20
Minimum Years Of Experience: #0_years
Deadline: December 16, 2023
How To Apply: Submit your applications (Cover Letter) including a detailed CV via email: [email protected]
N.B: Please title your application with the subject line: - " Area Sales Manager" and Specify the area you are applying for