TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #205 · 22 јан.

Как работает функция 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

Резултати

Пронајдени 50 слични објави

Пребарај: #raspberry

当前筛选 #raspberry清除筛选
Linuxgram 🐧

@linuxgram · Post #18754 · 12.05.2026 г., 08:32

📰 My Raspberry Pi 4 still has a job in my homelab, and it isn't Home Assistant I ran Home Assistant on a Raspberry Pi 4 for over a year. Though the Pi booted from an NVMe SSD, the Pi's 4GB memory limit became difficult to ignore as I built ESPHome devices. Recently, I moved Home Assistant to a mini PC and almost shelved the Pi, since it was just sitting in the corner doing nothing. 🔗 Source: https://www.xda-developers.com/raspberry-pi-4-homelab-without-home-assistant/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18710 · 08.05.2026 г., 10:51

📰 Your smart home needs both an ESP32 and Raspberry Pi 5, not one or the other For the past few months, I’ve been making the case for the ESP32. I'd argue that the $5 ESP32 microcontroller can easily replace the Raspberry Pi 5. That helps to save on cost and reduce the bulk. I still believe that. 🔗 Source: https://www.xda-developers.com/your-smart-home-needs-an-esp32-and-raspberry-pi/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18681 · 05.05.2026 г., 20:42

📰 Raspberry Pi Imager Now Supports Raspberry Pi Connect for Organizations Raspberry Pi Imager 2.0.9 flashing tool for Raspberry Pi devices is now available for download with support for Raspberry Pi Connect for Organizations and many other changes. 🔗 Source: https://9to5linux.com/raspberry-pi-imager-now-supports-raspberry-pi-connect-for-organizations #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18668 · 04.05.2026 г., 12:24

📰 Raspberry Pi 5's price hike pushed me toward mini PCs, and now I can't justify going back When Raspberry Pi 5 got a price hike, my first reaction was to pause and re-evaluate my plans. I’ve been running a Pi 4 as my home lab for years, and I've always wanted to upgrade to the Pi 5. After waiting for stock availability, I decided to take my requirements more seriously. 🔗 Source: https://www.xda-developers.com/raspberry-pi-5-price-hike-pushed-me-to-mini-pcs/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18660 · 03.05.2026 г., 07:31

📰 I replaced my Raspberry Pis with $5 ESP32s for smart home projects, and they do everything I need My smart home doesn't need a Raspberry Pi anymore, and the ESP32 just proved it. 🔗 Source: https://www.xda-developers.com/i-replaced-raspberry-pis-with-5-esp32s-for-home-assistant/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18639 · 01.05.2026 г., 07:59

📰 Running local AI on the Raspberry Pi 5 taught me why cloud models are still winning Except for Google's AI responses to searches, I've never used AI before, not once. Most people I know, when they hear this, say, "You haven't used AI? But it's so useful!" I disagreed; I'd seen the results Google's AI gave, and it honestly seemed overhyped. Then I thought about it and realized I couldn't really judge it without testing it. However, being into tech, I didn't want to risk my privacy, knowing the impact that can have, so I wanted... 🔗 Source: https://www.xda-developers.com/local-ai-raspberry-pi-5-positive-negative/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18570 · 25.04.2026 г., 20:47

📰 I turned a Raspberry Pi and mini PC into a portable homelab that fits in my backpack I love my homelab — but accessing it remotely from a hotel or café only gets me so far. That remote connection works fine for simpler tasks like checking dashboards, running scripts, waking up, or shutting down machines. But anything heavier — large file transfers, streaming, or running intensive workloads — quickly reveals public Wi-Fi’s limitations. 🔗 Source: https://www.xda-developers.com/turned-raspberry-pi-mini-pc-into-portable-homelab-that-fits-backpack/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18522 · 22.04.2026 г., 05:14

📰 Someone turned an ESP32 T-LoRa Pager into a portable music machine, and you can too While Raspberry Pis and ESP32s are great for hobbyists, they also regularly find themselves in products. They're very useful, after all, so it's only natural that companies will use them as their hardware of choice when making something small that doesn't need to be an absolute powerhouse. 🔗 Source: https://www.xda-developers.com/someone-turned-an-esp32-t-lora-pager-into-a-portable-music-machine-and-you-can-too/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18501 · 20.04.2026 г., 21:06

📰 I stopped trusting my router's diagnostics after my Raspberry Pi found what it missed Lately, I’ve been working on a lot of ESP32 projects, so I keep checking my router for connectivity. But those devices kept showing as connected even when powered off. That made me question whether my router was giving me the full picture. 🔗 Source: https://www.xda-developers.com/stopped-trusting-routers-diagnostics-after-raspberry-pi-found-what-missed/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18476 · 18.04.2026 г., 05:46

📰 My Raspberry Pi NAS taught me that cheap storage isn't worth the compromise A NAS without dependable storage is just a very patient disappointment. 🔗 Source: https://www.xda-developers.com/raspberry-pi-nas-taught-cheap-storage-isnt-worth-compromise/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18455 · 16.04.2026 г., 07:46

📰 Travel computing doesn't need a laptop — the Raspberry Pi 5 proved that to me For the right traveler, the Raspberry Pi 5 is more than just adequate on the road. 🔗 Source: https://www.xda-developers.com/travel-computing-doesnt-need-laptop-raspberry-pi-5-proved/ #raspberry

Hashtags

Linuxgram 🐧

@linuxgram · Post #18445 · 15.04.2026 г., 12:18

📰Raspberry Pi OS ends open-door policy for sudo Command prefix will require password by default The latest version of Raspberry Pi OS now requires a password for sudo by default.… 🔗 Source: https://go.theregister.com/feed/www.theregister.com/2026/04/15/raspberry_pi_os_sudo/ #raspberry

Hashtags

ПретходнаСтраница 1 од 5Следна