Ранее мы уже говорили о том, как выполнить какой-либо код перед открытием интерактивной консоли.
Расскажу еще один способ! На самом деле, даже запустив интерпретатор в обычном режиме с выполнением скрипта из файла вы можете в любом месте активировать интерактивный режим. Или даже несколько по очереди. За это отвечает модуль 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
📣 Open Call: Entertainment & Creative Economy Startups!
Plug and Play Central Asia & IT Park Uzbekistan are launching Batch 6! We are looking for global innovators ready to scale.
We are seeking solutions in:
🎮 GameDev
👓 Immersive Tech (AR/VR, Metaverse 2.0, Content Monetization & Video Editing)
✈️ Travel & Tourism
Why join?
✨ Potential investment from IT Park Ventures
✨ Access to Silicon Valley via our GOAL Program
✨ Expert mentorship & global corporate network
✨ Pitch at the Batch 6 Expo in May 2026
📅 Deadline: January 15, 2026
🔗Apply here: https://www.plugandplaytechcenter.com/locations/uzbekistan
Let’s build the future together! 🚀
#PlugAndPlayCA#Startups#CreativeEconomy#GameDev#TravelTech#Uzbekistan
📣 Open Call: Enterprise & AI Startups — Your Moment Is Now!
🚀 Plug and Play Central Asia, in partnership with IT Park Uzbekistan, is on the lookout for high-potential startups from Central Asia and around the globe to join Batch 5 of Plug and Play Tech Center Accelerator Program in Uzbekistan.
Who should apply?
✔️ International startups ready to expand into Central Asia and establish a footprint in Uzbekistan
✔️ Homegrown Uzbekistan-based startups looking to scale fast with world-class support
✔️ High-growth startups with real traction and global ambition
What’s in it for you?
✔️ Expert mentorship and hands-on support from Plug and Play's global network
✔️ Investment opportunities and warm intros to VCs
✔️ Exclusive access to pitch at our Expo in front of corporates and investors
✔️ Practical workshops and pitch training sessions
✔️ The chance to join Plug and Play Tech Center GOAL Program in Silicon Valley and visit other locations
IT Park Ventures will review all participating startups for investment - supporting international startups considering entering Uzbekistan and helping local founders scale worldwide.
Applications are open here:link
🗓 Deadline to apply: July 15, 2025
🟢 Selected startups will be announced in August. The program kicks off in early October.
Apply now and let’s build the future together!
#PNPTC#PlugAndPlayCA#Uzbekistan#Accelerator#Batch5#OpenCall#ITPark
📣 Open Call: Enterprise & AI Startups — Your Moment Is Now!
🚀 Plug and Play Central Asia, in partnership with IT Park Uzbekistan, is on the lookout for high-potential startups from Central Asia and around the globe to join Batch 5 of Plug and Play Tech Center Accelerator Program in Uzbekistan.
Who should apply?
✔️ International startups ready to expand into Central Asia and establish a footprint in Uzbekistan
✔️ Homegrown Uzbekistan-based startups looking to scale fast with world-class support
✔️ High-growth startups with real traction and global ambition
What’s in it for you?
✔️ Expert mentorship and hands-on support from Plug and Play's global network
✔️ Investment opportunities and warm intros to VCs
✔️ Exclusive access to pitch at our Expo in front of corporates and investors
✔️ Practical workshops and pitch training sessions
✔️ The chance to join Plug and Play Tech Center GOAL Program in Silicon Valley and visit other locations
IT Park Ventures will review all participating startups for investment - supporting international startups considering entering Uzbekistan and helping local founders scale worldwide.
Applications are open here:link
🗓 Deadline to apply: July 15, 2025
🟢 Selected startups will be announced in August. The program kicks off in early October.
Apply now and let’s build the future together!
#PNPTC#PlugAndPlayCA#Uzbekistan#Accelerator#Batch5#OpenCall#ITPark