Ранее мы уже говорили о том, как выполнить какой-либо код перед открытием интерактивной консоли.
Расскажу еще один способ! На самом деле, даже запустив интерпретатор в обычном режиме с выполнением скрипта из файла вы можете в любом месте активировать интерактивный режим. Или даже несколько по очереди. За это отвечает модуль 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
⚡️Fanton EN: Exciting EPL Midweek Tournament!
#EPL#prizes
Fanton EN is hosting an exciting English Premier League tournament with a $200 prize pool. Don’t miss the matches from December 2-4, including Newcastle vs Tottenham and Fulham vs Man City. Join now with a $9 entry fee and compete for the prize!
Source: link
@tonlines
Gatto | Official Channel: Legendary Crocottery Results Announced
#raffle#prizes
The Gatto | Official Channel has announced the winners of the Legendary Crocottery raffle. Luck has determined the prize recipients, who will receive their rewards within a week. Participants can check the results by finding their id in the linked table.
Source: link
@tonlines
Getting ready for an upcoming 𝐆𝐏𝐓𝟑𝟔𝟎 event with a $𝟑𝟎𝟎 𝐩𝐫𝐢𝐳𝐞 𝐩𝐨𝐨𝐥, we've decided to have a token giveaway! ⭐️📣
❓ 𝐖𝐇𝐀𝐓 𝐓𝐎 𝐃𝐎:
1) Like and Retweet thisPost - https://twitter.com/GPT360_Official/status/1745035636208279760
2) Tag 3 friends in the comments
3) Add Hashtags#GPT360#Giveaway#Prizes
👑 𝐏𝐑𝐈𝐙𝐄 𝐏𝐋𝐀𝐂𝐄𝐒:
1st Place - 1500 TestNet Tokens
2nd Place - 1500 TestNet Tokens
3rd Place - 1500 TestNet Tokens
All participants will enter the draw, and three lucky winners will be randomly chosen on Friday! 🎉🍀
GIVEAWAY ALERT🎉
🎁Prizes: 5 $TON for 5 random winners from the comments on X!
⏰DURATION: 48 hours to enter, so hop in now!
How to join:
1. Follow us on X
2. Jump into our Telegram channel
3. Like & RT the first post
4. Tag 3 of your besties in the comments on X!
➡️Let’s go!
Remember, you gotta be following our X account to win!
Good luck!
#Giveaway#TonEvents#Airdrop#Fun#Prizes#Friends#X
⭐️ Telegram Star Giveaway on X🧦
🎁Prizes: 500 ⭐️ Telegram Stars for 5 random winners from the comments on X!
⏰DURATION: 48 hours to enter, so hop in now!
How to join:
1. Follow us on X👈
2. Jump into our Telegram channel
3. Like & RT the post
4. Tag someone in the comments on X!
➡️Let’s go!
Remember, you gotta be following our X account to win! Good luck!
#Giveaway#TonEvents#Airdrop#Fun#Prizes#Friends#X#TelegramStars