PhewphewMathew
PhewphewMathew

Reputation: 57

How to fix that Sublime Text runs a wrong file from its command terminal?

I have 2 .py files that called tag_to_top.py and color_changer.py. Each file is contained in their individual package folders so they are completely separated. They have different file directories.

Now here's the problem. When I run the file called color_changer.py using view.run_command("color_changer") inside of the Sublime Text terminal, the output does not match what it should be from the color_changer.py. It seems like the terminal of ST runs different code.

Here are the details of the code

# tag_to_top.py
import sublime
import sublime_plugin

class TagToTopCommand(sublime_plugin.TextCommand):
    def run(self, edit, tag=None):
        tag_lines = self.view.find_all(r"^\s*((#\w+)\s*){1,}")
        print()
        print("hello world 2")

# color_changer.py
import sublime
import sublime_plugin

file_path = './log.txt'

with open(file_path, 'r') as f:
    for line_number, line in enumerate(f, start=1):
        if line.startswith(r'\s'):
            num_empty_spaces = len(line) - len(line.lstrip())
            print(f"Line {line_number}: {num_empty_spaces} empty spaces")
    

The output from the code is fixed to a result of tag_to_top.py, (empty line) \n hello world 2. No matter which files run inside of the terminal, it always throws the same output.

When I run tag_to_top.py, throws the result of tag_to_top.py,

When I run color_changer.py, it also throws the result of tag_to_top.py.

Are there any ways to fix this without re-installing ST?

Upvotes: 0

Views: 34

Answers (0)

Related Questions