Как работает функция 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
🌎 Fire rainbows, officially called circumhorizontal arcs, are rare displays where sunlight passes through ice crystals in cirrus clouds at just the right angle. These arcs appear only when the Sun is high—above 58°—and the ice crystals align horizontally, producing brilliant, rainbow-colored bands across the sky. ✨
#atmosphere⚡#optics⚡#weather
👉subscribe Interesting Planet
👉more Channels
🌍 A rare atmospheric optical event called a "glory" creates shimmering, colored rings around the shadow of an observer’s head on clouds or fog. This effect is caused by sunlight scattering in tiny water droplets. ✨
#aurora⚡#optics⚡#atmosphere⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The vivid red auroras seen during strong solar storms are caused by oxygen atoms glowing high above 200 kilometers—twice as high as typical green auroras visible near the poles. ✨
#aurora⚡#atmosphere⚡#optics⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Sundogs are bright spots that appear on either side of the Sun when its light passes through ice crystals in the air, creating colorful halos—an atmospheric optical effect seen even in cold, clear weather. ✨
#aurora⚡#optics⚡#atmosphere⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Extremely rare "fire rainbow" clouds appear when sunlight hits ice crystals in high clouds at just the right angle, creating brilliant bands of color that stretch across the daytime sky. ✨
#aurora⚡#optics⚡#atmosphere⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The rarest aurora color is deep blue, caused by high-energy solar particles colliding with nitrogen over 100 kilometers up. Most auroras are green or red, but blue glows only appear during strong solar storms. ✨
#aurora⚡#atmosphere⚡#optics⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Polar stratospheric clouds can trigger vivid pink and orange auroras when solar storms are strong. These rare clouds form high above the Arctic, scattering light in unique, shimmering patterns. ✨
#aurora⚡#atmosphere⚡#optics⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 The elusive "Steve" aurora glows as a narrow purple ribbon in the night sky. Only recognized in recent years, it’s linked to fast-moving hot gases high above Earth’s atmosphere. ✨
#aurora⚡#atmosphere⚡#optics⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
🌍 Rare atmospheric optics called circumhorizontal arcs appear when sunlight passes through high ice clouds at just the right angle, creating bands of rainbow colors that stretch parallel to the horizon. ✨
#aurora⚡#optics⚡#atmosphere⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍
🌍 The “green flash” is a rare weather phenomenon seen at sunrise or sunset, caused by sunlight bending in the atmosphere. For a second, the top edge of the sun glows vivid green. ✨
#meteorology⚡#atmosphere⚡#optics⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography
👉more Channels
📰 Mar-a-Lago: Where Power, Marble, and Ice Sculptures Collide
President Trump’s presidency has become a permanent residency at Mar-a-Lago—where official governance, private business, and personal relationships converge in a swirl of marble, ice sculptures, and political optics.
This week, Trump’s motorcade pulled into an industrial shopping center to inspect samples of marble and onyx for a proposed White House ballroom. The purchase is “at his own expense,” a White House official said, but the timing is suspicious: construction can’t begin until federal review, and the ballroom project has already attracted scrutiny over donor influence and potential payoffs.
Trump has hosted foreign leaders, conducted diplomacy, and even overseen a military strike on Venezuela—all from his Florida estate. His social calendar is just as packed: 12 golf outings in two weeks, a New Year’s Eve party where guests bid $2.75 million on a live-painted portrait of Jesus, and a caviar station with a “2026” ice sculpture.
Democrats have seized on the spectacle, contrasting the opulence with the impact of Trump’s policies. As millions lose health insurance and food aid, critics highlight the disconnect:
“Trump is kicking poor kids off food aid and is throwing millions off their health care this month, but he and his billionaires get caviar and ice sculptures,”
Senator Chris Murphy wrote.
The White House fires back, accusing Democrats of gaslighting and pointing to Biden’s vacations. But the optics remain: Mar-a-Lago is now shorthand for a presidency where wealth, access, and official decision-making are intertwined.
So while Trump touts his accomplishments from the stage, one question lingers: Who’s really running the country—the president, or the party?
#Trump#MaraLago#WhiteHouse#politics#optics
📱American Оbserver - Stay up to date on all important events
🇺🇸
🌍 Sometimes, sunlight or moonlight passing through a layer of ice crystals high in the sky creates sun pillars or light pillars—vertical beams that appear to rise above the horizon. ✨
#auroras⚡#optics⚡#atmosphere⚡#geography⚡#nature⚡#earth
👉subscribe Amazing Geography🌍