Как работает функция 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
💥Simple guide on Soneium
Galxe quest
✅L2 By Sony 💿
💯FREE
👇Steps
🔗https://app.galxe.com/quest/Soneium/
✅Complete social task
✅Go to second quest page
✅Complete social task
✅Mint first day NFT
✅Mint daily NFTs
✅Claim points
💥Done
#Soneium
💿 Soneium is now live on TokenPocket!
#Soneium is a Layer 2 blockchain that empowers creators, fans, and communities to protect their rights, connect globally, and build an open internet that transcends boundaries.
💙Get started to easily create, import, and sync your #Soneium wallet on TokenPocket!
👉https://tokenpocket.pro
Crypto Funds Struggle Compared to Bitcoin
OKX's founder Star claims no crypto fund has outperformed Bitcoin over the last decade, predicting a 100x growth for the industry. He acknowledged feedback on OKB's lack of use cases and poor listings. A new secret business line for OKX is set to launch in February.
In other news, Ethereum spot ETFs saw a net outflow of $39.432 million, while Bitcoin ETFs faced a larger outflow of $284 million. Notably, BlackRock's ETHA and IBIT ETFs saw significant inflows.
Read more about OKX's updates here, Ethereum's ETF activity here, and Bitcoin's ETF activity here.
#OKX#Bitcoin#Ethereum#Crypto#ETFs#BlackRock#OKB#NFTs#Web3#DeFi#Soneium#S.BLOX #Blockchain#Investing#Finance#BitcoinETF#EthereumETF#VC#AI
Sony Launches Blockchain Platform Soneium
Sony's public blockchain platform, *Soneium*, has officially launched on the mainnet. This initiative aims to enhance its technology offerings in the blockchain space. Read more here.
In a historic move, Italy's largest bank, *Intesa Sanpaolo*, has purchased 11 bitcoins valued at around €1 million, marking the first direct crypto transaction by a financial institution in Italy. Details can be found here.
FTX/Alameda has redeemed and transferred 182,421 SOL (approx. $32.35M) today, raising the total since last November to 4.445M SOL (approx. $516.88M). The staked address currently holds 6.47 million SOL (approx. $1.18B). More information here.
The US Court of Appeals ruled in favor of *Coinbase* in its case against the SEC, deeming the SEC's denial of rulemaking as “arbitrary and capricious.” This case revolves around establishing rules for digitally native asset securities. For further reading, click here.
#Sony#Blockchain#Soneium#Bitcoin#ECB#Italy#IntesaSanpaolo#CryptoTransactions#FTX#SOL#Coinbase#SEC#DeFi#DigitalAssets#Cryptocurrency#Finance#Investing#VentureCapital#CryptoNews#CryptoMarket