Forum Archive

Access Pythonista Settings from Script

Harum_Scarum

I’d like to write a script that checks the Pythonista settings from within the script. Specifically, I’d like to check the indentation settings - whether they are tabs or spaces, and the number of spaces. I couldn’t find anything on this topic in the documentation or forum, but sorry if I missed something on this topic. Any suggestions on how I might reference this information?

cvp

@Harum_Scarum try something like

import editor
def main():
    indent = '?'
    f = editor.get_text()
    lines = f.split('\n')
    for line in lines:
        if not line:
            continue
        if line[0] == '\t':
            indent = 'tab'
            break
        elif line[0] == ' ':
            n = len(line) - len(line.lstrip())
            indent = str(n)+ ' blanks'  
            break
    print(indent)   

main()
cvp

@Harum_Scarum sorry, my script finds what you do, not what the setting value is.

JonB
from objc_util import *
>>> defaults=ObjCClass('NSUserDefaults').standardUserDefaults()
>>> defaultsDict=defaults.dictionaryRepresentation()
>>> defaultsDict['UseSoftTabs']
<b'__NSCFBoolean': 1>
>>> defaultsDict['IndentationWidth']
<b'__NSCFNumber': 3>

type defaultsDict at the console to see all of the pythonista settings that you can check this way.

cvp

@JonB wow

Harum_Scarum

Thank you!