Ранее мы уже говорили о том, как выполнить какой-либо код перед открытием интерактивной консоли.
Расскажу еще один способ! На самом деле, даже запустив интерпретатор в обычном режиме с выполнением скрипта из файла вы можете в любом месте активировать интерактивный режим. Или даже несколько по очереди. За это отвечает модуль code.
Как это может пригодиться?
🔸 Вам не хватает pdb и хочется больше "власти"
🔸 Нужно запросить у юзера данные в достаточно сложном виде. В этом случае можно попросить его создать что ему надо и сохранить в определённую переменную, с которой потом и работать.
🔸 Нужна изолированная среда для выполнения каких-либо действий.
🔸 Просто забавы ради😁
Запускается консоль очень просто
import code
ic = code.InteractiveConsole()
try:
ic.interact()
except SystemExit:
pass
Выход обратно на предыдущий уровень происходит как обычно, вызов функции exit() или клавиши Ctrl+D(Ctrl+Z для Windows).
Я набросал простой пример с некоторым функционалом
🔹 Меняются символы приглашения
🔹 В неймспейсы добавляются дополнительные объекты
🔹 Считается время, проведённое в интерактивном режиме
🔹 Скрипт просит юзера заполнить переменную и по выходу распечатывает её значение
Код здесь ↗️
Для запуска сохраните код в файл и запускайте как обычный скрипт.
python my_console.py
Для быстрого запуска можно сделать отдельный алиас
alias py="python3 /home/username/my_console.py"
#tricks#source
@RusEmbMalta press release: Situation around #Ukraine.
🔷 Root causes of the conflict over Ukraine;
🔷 Role of the “collective West” countries;
🔷Western equipment and hostilities by the Kiev regime;
🔷 Settlement prospects;
🔷 Mediation initiatives;
🔷 Grain Deal;
🔷 Situation around the Ukrainian
Orthodox Church of the Moscow Patriarchate (UOC MP);
🔷 About the conference in Switzerland.
#TruthOnUkraine
@RusEmbMalta:
On November 3, 2025, the Times of Malta published a commentary by the Russian Ambassador to Malta, Andrey Lopukhov, responding to the editorial of October 19, 2025
📰 In his commentary, Ambassador Lopukhov emphasized the importance of relying on verified facts when assessing the situation in Ukraine and warned against the spread of misinformation.
Key points:
🔹 the so-called “Ukrainian crisis” began not in February 2022, but with the coup d’état in Kiev in 2014;
🔹 for years, the Kiev authorities pursued policies of discrimination and violence against Russian-speaking citizens;
🔹 the Odessa tragedy of May 2014 remains an uninvestigated crime;
🔹 Western arms supplies and financial support to Kiev only deepen the crisis;
🔹 Russia has consistently raised the issue of human-rights violations by the Kiev regime, despite the West’s unwillingness to listen;
🔹 millions of people around the world believed Russia – because truth, however suppressed, always breaks through lies and propaganda.
💬“There are facts that cannot be denied. And it is those very facts that made people across the world see what was happening with their own eyes and draw their own conclusions.”
🔗 Read the full text of the commentary onTimes of Malta.
#UkrainianCrisis#TruthOnUkraine#TruthMatters