Ранее мы уже говорили о том, как выполнить какой-либо код перед открытием интерактивной консоли.
Расскажу еще один способ! На самом деле, даже запустив интерпретатор в обычном режиме с выполнением скрипта из файла вы можете в любом месте активировать интерактивный режим. Или даже несколько по очереди. За это отвечает модуль 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
🚀 The speed of the bot has increased and the problem of unresponsiveness has been solved
We have also added a new task for you to get 5,000 tokens in 3 seconds ☕️
Most importantly, if you send a photo to the bot, you can edit it much more easily and...
Try it😉
💎https://t.me/chatgpt_officialbot
If you have any problems or find a bug, send a message to support and get a bunch of free tokens:@OpenAI_helpdesk🔥
➖➖➖➖🔻
🧠 BOT: @Chatgpt_OfficialBOT
💎@Chatgpt_OfficialNews
#️⃣#Bot#Fix#Photo#Update
➖➖➖➖🔺
Remember when you used to run out of tokens and watching ads felt so boring and time-consuming?
😅
Now, the “Fast Free Tokens” task section has been completely redesigned to be much simpler and clearer.
Plus, we’ve added new tasks that let you earn free tokens in just 3 seconds! 🎁
No more hassle — just fast, easy, and unlimited fun with AI 🤖✨
⚡️ Some of you mentioned bugs and slow performance — they’re all fixed now!
The bot is much smoother and faster than before.
🖼 There was also an issue with photo editing being inaccurate or glitchy sometimes.
Now that part is stronger than ever — with higher precision, fewer bugs, and no increase in token prices, you can edit your photos exactly how you like 🔥
Give it a try — we’re sure you’ll love it 😉
@chatgpt_officialbot
➖➖➖➖🔻
🧠 BOT: @Chatgpt_OfficialBOT
💎@Chatgpt_OfficialNews
#️⃣#Bot#Fix#Photo#Update
➖➖➖➖🔺
Fix: Unable to make changes as organizer of Family Sharing
Learn what to do if you are unable to make important changes to Screen Time,
subscriptions, and other settings for family members.
via iDB - Mac
标签: #make#changes#Fix
⚡️探索号频道
⚡️探索者频道
⚡️探索者交流群
⚡️ Youtube 频道:科技探索者
每天推荐有趣内容,欢迎订阅、转发。