Recently I switched Python coding from IDLE to Sublime Text and coded the following program:
while True:
code = input("Code >>> ")
if "show(" in code and ")" in code:
print(code[code.index("(") + 2:code.index(")") - 1])
elif "terminate" in code:
print("SHUTTING DOWN...")
break
else:
print("Error Caught: Unknown Syntax")
But when I type the code show("Hello World!")
it didn’t work.

There wasn’t any code error, and the program worked in IDLE, but to no avail in Sublime Text. I checked if any packages were obstructing the execution but none.
I tried running the line print("Hello World!")
in Sublime Text but also it didn’t work.
Please help me fix the issue
Hi @aditya2010.kadiyala Try the below code and do let me know if it helps
while True:
code = input("Code >>> ")
if "show(" in code and ")" in code:
print(code[code.index("(") + 1:code.index(")")])
elif "terminate" in code:
print("SHUTTING DOWN...")
break
else:
print("Error Caught: Unknown Syntax")
Hi @himanshu.arya
No, I tried running the code but it didn’t work yet again. It seems like a problem in the Sublime Text Python Compiler. I even tried reinstalling the software to no avail.
The function print("Hello World!")
and the above code doesn’t work in Sublime Text. I checked the code in IDLE and other compilers and it worked.
You can use Visual Studio Code for your python codes. Or, you can also use Jupyter Notebook.
Hi, @aditya2010.kadiyala
Based on the code you provided, it seems that the issue is with the way you are extracting the substring between the parentheses in the show()
command. Please try this code:
while True:
code = input(“Code >>> “)
if “show(” in code and “)” in code:
print(code[code.index(”(”) + 1:code.index(“)”)])
elif “terminate” in code:
print(“SHUTTING DOWN…”)
break
else:
print(“Error Caught: Unknown Syntax”)
In the corrected code, I made the following changes:
- In the
print
statement inside the if
condition, I adjusted the substring extraction to code.index("(") + 1
and code.index(")")
without the -1
after the closing parenthesis. This ensures that the substring between the parentheses is correctly extracted.
Now, when you enter show("Hello World!")
, it should correctly print Hello World!
as the output.
Regarding running the code in Sublime Text, it is an integrated development environment (IDE) that provides a text editor for writing code. It doesn’t execute code directly like IDLE does. To run Python code in Sublime Text, you need to configure a build system. Here’s a simple way to do it:
- Open Sublime Text and go to
Tools > Build System > New Build System
.
- Replace the empty JSON file with the following code:
{
“cmd”: [“python3”, “-u”, “$file”],
“file_regex”: “^[ ]File "(…?)", line ([0-9]*)”,
“selector”: “source.python”
}
- Save the file with a descriptive name like “Python3.sublime-build”.
- Now, you can select
Tools > Build System > Python3
or press Ctrl+B
(Windows/Linux) or Cmd+B
(Mac) to run your Python code.
Make sure you have Python installed on your system and properly set up in your system’s PATH environment variable.