Как работает функция 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
#JavaScript#Beginners
🧰
JavaScript for Beginners
The JavaScript for Beginners course aims to teach students who are new to JavaScript the fundamentals of the programming language. The course is taught by Darragh O’Neill a Udemy Instructor who has has received excellent reviews on the platform and has at present a 4.7 star rating.
The course also contains several mini-projects and challenges so we can apply the JavaScript syntax that we have learnt. The course has overs 13+ hours of content and by the end of this course students will be familiar with all the fundamental aspects of the JavaScript language including data types, variables, let, const var, arrays, objects, functions, manipulating the DOM and more.
🔗Link
-----
Canal principal:@repo_science
Cupones: @freecoupons_reposcience
-----
#Python#Excel#beginners
💻
Python in Excel
🗣 Scott Simpson
⏰30m
Get a high-level overview of the Python in Excel features launched in the public beta preview.
-----
Main channel: @repo_science
Coupons: @freecoupons_reposcience
-----
😁Blue Print To Beginner: Intermediate Leglocks By Tom DeBlass😁
➡️Attack The Lower Body With Highly Effective Submission Locks, Taught By One Of Grappling’s Most In-Demand Instructors - Tom DeBlass
➡️Tom DeBlass is a Renzo Gracie black belt who has spent years training with, learning from, and training some of the best grapplers and instructors in all of Brazilian jiu-jitsu - including Gordon Ryan, Garry Tonon, and more
➡️Set up your attacks from common grappling positions like the butterfly guard, closed guard, half guard, and more as Tom shares how to learn faster and cut through the mistakes easier
$127😍$11.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#TomDeblass#Leglocks#Beginners#NoGi
💁♀️Buy
💁♀️
#ruby#beginners#hacktoberfest#hacktoberfest2020#helm#kubernetes#kubetools
Kubernetes is a powerful tool for managing containerized applications. To learn Kubernetes, you can use platforms like Kubelabs, which offer interactive tutorials and labs. These resources help you understand Kubernetes concepts from the basics to advanced levels. By using these platforms, you can practice deploying applications, managing resources, and ensuring high availability and scalability. This hands-on approach helps you gain practical experience and improve your skills in managing complex applications efficiently.
https://github.com/collabnix/kubelabs
#webScraping#Python#Scrapy
🐍
Scrapy course - Python web scraping for beginners
The Scrapy #Beginners Course will teach you everything you need to learn to start scraping websites at scale using #Python Scrapy.
Topics
- Creating your first #Scrapy spider
- #Crawling through websites & scraping data from each page
- Cleaning data with Items & Item Pipelines
- Saving data to CSV files, #MySQL & #Postgres#databases
- Using fake #user-agents & headers to avoid getting blocked
- Using #proxies to scale up your web scraping without getting banned
- Deploying your #scraper to the cloud & scheduling it to run periodically
🗣️ Joe Kearney.
🔗Link
📢#youtube
⭐️ Resources ⭐️
Course Resources
- Scrapy Docs
- Course Guide
- Course Github
- The Python Scrapy Playbook
-----
Main channel: @repo_science
Coupons: @freecoupons_reposcience
-----