Sublime Forum

Retrieving a value set in a .sublime-settings file

#1

I have the following folder structure :

resources\
    settings\
        MySettings.sublime-settings
    commands\
    keymaps\

foo_bar.py

The MySettings.sublime-settings is as follows:

{
    "some_value": 10
}

How do I retrieve some_value in my foo_bar.py file ? I checked the API docs for sublime.load_settings() but it says I have to give it a file name and not a path.

For the sake of an example, foo_bar.py can be:

import sublime
import sublime_plugin

class FooBarCommand(...):

    def run(self):
        # I tried setting the path but the value is coming out to be None
        settings = sublime.load_settings()
        value = settings.get("some_value")

Sublime Build : 3211
Windows 7, 64 bit OS.

0 Likes

#2

try sublime.load_settings('MySettings.sublime-settings')

1 Like

#3

just to check, if you don’t keep the settings file in a subfolder of your package, everything works fine?

0 Likes

#4

I kinda feel like hiding under a rock now :see_no_evil:. Thanks. That worked

0 Likes

#5

So does that mean the API can find the settings file no matter it’s location in a package ?

0 Likes

#6

I am not sure since all my plugins put the settings file under the package root. If you put your package settings under a subdir and it can still be loaded by sublime.load_settings('MySettings.sublime-settings') then I think yes.

0 Likes