1. Briefly
I don’t find in Google, how I can remove "quotes"
, if I insert Python variable in another variable.
2. Expected behavior
I write small plugin for split current file:
# Swiss File Knife split utility:
# http://stahlworks.com/dev/index.php?tool=split
class grace_splitter_sfk_knife(sublime_plugin.TextCommand):
def run(self, edit):
FILE_PATH = self.view.file_name()
if(FILE_PATH):
command = ["sfk", "split", "100k", "-yes", "-text", FILE_PATH]
print(command)
subprocess.Popen(command, shell=True)
If I run command:
- command successful work for me,
- I get in Sublime Text console:
command: grace_splitter_sfk_knife
['sfk', 'split', '100k', '-yes', '-text', 'D:\\Test\\SashaLog.log']
3. Actual behavior
Now I want, that user may run custom command, which user set in user settings.
My GraceSplitter.sublime-settings
file:
{
"gracesplitter_cmd_options": "sfk split 100k -yes -text"
}
My class:
# Custom split command
class grace_splitter_custom_splitter(sublime_plugin.TextCommand):
def run(self, edit):
FILE_PATH = self.view.file_name()
if(FILE_PATH):
# Get Sublime Text settings —
# http://stackoverflow.com/a/14186945/5951529
settings = sublime.load_settings(
'GraceSplitter.sublime-settings')
cmd_options = settings.get(
'gracesplitter_cmd_options')
# Split settings — http://stackoverflow.com/a/743824/5951529
cmd_options_split = cmd_options.split()
# Method strip —
# https://www.tutorialspoint.com/python/string_strip.htm
strip_brackets = str(cmd_options_split).strip('[]')
command = strip_brackets, FILE_PATH
print(command)
subprocess.call(command, shell=True)
If I run command:
- command don’t work for me,
- I get in Sublime Text console:
command: grace_splitter_custom_splitter
["'sfk', 'split', '100k', '-yes', '-text'", 'D:\\Test\\SashaLog.log']
How I can get expected behavior?
3. Did not help
- I try make other value for variable
command
:
command = '[' + strip_brackets + ',' + \
' \'' + FILE_PATH + '\'' + ']'
I get in Sublime Text console:
command: grace_splitter_custom_splitter
['sfk', 'split', '100k', '-yes', '-text', 'D:\Test\SashaLog.log']
Command don’t work for me again.
Thanks.