sublimetextsublime-text-plugin

sublime text plugin help: How to output to console using print in python


I am using a plugin in sublime text called Sidebar Enhancements.

One of its functionality has some issue. So i added few print statements in the source code of the plugin

I am not able to see the print statements output in the console which I have put in the source code

Example something like this i changed the source code to.

class SideBarFilesOpenWithCommand(sublime_plugin.WindowCommand):
    def run(self, paths=[], application="", extensions="", args=[], multiple=False):
        print("Hello World")

I am expecting the Hello World to appear in the console (ctrl + `)

i.e

enter image description here


Solution

  • print() does go to console. I briefly thought it wasn't (which lead to some searching and finding this post) but I think my issue was an async callback, user error, or some other bit of computer nonsense that I haven't reproduced.

    Make sure you don't accidentally have multiple copies of the code. You can add top level prints to ensure the file you are changing is the right file.

    I made a demo using Tools > Developer > New Plugin... and saved it as delete.py,

    import sublime_plugin
    
    print('This plugin has been loaded.')
    
    
    class DemoSideBarFilesOpenWithCommand(sublime_plugin.WindowCommand):
        def run(self, paths=[], application="", extensions="", args=[], multiple=False):
            print("Hello World, I am working!")
    

    Then ran it in the console window.run_command('demo_side_bar_files_open_with')

    You can see after "reloading plugin User.delete" has the print, so I know I have the right file, and that calling the command works. You might also need to restart sublime, there could be some code caching issue, I don't know if user plugins are treated differently than other ones. Even this, though, could hide something, maybe I saved it to the wrong folder, but it has much more info than blurring out most of the image.

    I'd also recommend making a little demo so you don't need to blur as much for privacy, or whatever other concerns you have. I get that you were trying to be clear where you expected the print to be but there might be some hint that gets covered up.

    For this screenshot I pulled off the tab then just covered up most of the filename as an example.

    Good luck sleuthing!

    Example sublime plugin printing to console