Как работает функция 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 | Campesino Movements Demand Venezuelan Gov’t Step In to Protect Activists from ‘Criminalization’ Attacks
Venezuelan campesino movements have denounced the arrest of Lilibeth Rangel in Zulia and the detention of 28 rural producers in Barinas as part of a broader pattern of criminalization.
The Small Farmers Movement (MPA) is urging government institutions to intervene and address judicial delays and alleged landowner interference in security operations. Campesino families from La Rubiera and La Fortuna estates have been demanding land titles under the 2001 Land Law for years.
🔗 Read the full report here: https://venezuelanalysis.com/news/campesino-movements-demand-venezuelan-govt-step-in-to-protect-activists-from-criminalization-attacks/
#Peasants#Campesinos
On September 21, Venezuelan campesino leader Iraidez Andrade was killed by masked hitmen in Barinas state.
He had been a prominent voice in the Las Mercedes land struggle and was working with local communities to secure land for campesino families. Rural organizations have called for justice and an end to impunity for the ongoing violence against campesino leaders.
Full report here 👉🏼https://shorturl.at/dzgzG
#Peasants#Campesinos
📹 VIDEO | Rice Producers Protest Agribusiness Pressure in Venezuela
Rice producers across Venezuela are taking to the streets ahead of the upcoming harvest, warning that prices offered by agroindustrial firms could leave many farmers unable to cover production costs.
Campesino groups say large conglomerates are using their control over silos, imports, and distribution to push prices down, while limited access to credit keeps farmers dependent on company financing.
After talks with producers, Agriculture Minister Julio León Heredia announced a provisional price. But campesino organizations warn they were barely represented in negotiations.
Click here to read our full report 👉🏾https://venezuelanalysis.com/news/venezuela-rice-producers-denounce-agribusiness-pressure-demand-govt-support-for-fair-prices/
#Agriculture#Peasants#Campesinos
📰 NEWS | Venezuela: Rice Producers Denounce Agribusiness Pressure, Demand Gov’t Support for Fair Prices
Venezuelan rice producers have staged demonstrations in Barinas, Cojedes, Guárico and Portuguesa, demanding state action to secure fair prices for their crops.
According to producer representative Víctor Martínez, agribusiness firms are offering $0.32–0.38 per kilo ahead of harvest, compared to $0.50–0.55 last year. Producers have set a $0.70 per kilo target in negotiations, citing rising input costs and lack of credit access.
Growers also report financing agreements in which companies provide inputs and collect up to 60% of the crop as payment. Campesino organizations are considering a rally in Caracas. Government officials have not yet commented.
Read the full report here 👉🏾https://venezuelanalysis.com/news/venezuela-rice-producers-denounce-agribusiness-pressure-demand-govt-support-for-fair-prices/
#Agriculture#Peasants#Campesinos
📰 NEWS | Venezuela: Turkish Investors to Take Over State-Owned Sugar Mills Under ‘Strategic Alliances’
Venezuela has signed agreements with Turkish investors to manage three state-owned sugar mills — Central Venezuela (Zulia state), Santa Clara (Yaracuy state), and Ezequiel Zamora (Barinas state) — as part of new 'strategic alliances,' Agriculture Minister Julio León announced.
Authorities have not disclosed further details. Previous experiences with similar alliances in the countryside have raised concerns among campesinos regarding transparency and impacts on small-scale producers.
🔗 Read the full report here: https://shorturl.at/pwPmt
#Peasants#Campesinos#PrivateSector#Sugar
🖊 COLUMN | Venezuela, Popular Power and Coffee
Jessica Dos Santos' latest column showcases how 18 communes in Sanare, Venezuela, launched the “Enriquito Colmenárez” coffee-roasting plant after receiving it from the Agriculture Ministry.
The grassroots initiative supports campesinos with subsidies, training, and direct diesel access, while preparing to export robusta beans to the US and Russia. The plant will also host a soil lab through a partnership with the United Nations Food and Agriculture Organization (FAO).
🔗 Read the full VA column here: https://shorturl.at/EAU4t
#Coffee#Peasants#Campesinos#PopularPower#TalesofResistance