JensDiemer

Um Einstellungen vorzunehmen kann man diese in SciTEUser.properties speichern.

Am einfachsten:

  • SciTE starten
  • auf Options / Open User Options File gehen
  • Nun ist SciTEUser.properties geöffnet

Meine SciTEUser.properties für Python

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Fensterposition beim Start von SciTE
position.left=50
position.top=40
position.width=1550
position.height=900

# Ausgabefenster neben dem SourceCode-Fenster
split.vertical=1

# Ausgabefenster konfigurieren
output.scroll=1
output.horizontal.size=730

# Vertikale Linie zur Textberenzung auf 79 Zeichen
edge.column=79
edge.mode=1
edge.colour=#dddddd

# ähnlich Tab-Browsing: Mehrere Dateien gleichzeitig öffnen
tabbar.visible=1
statusbar.visible=1
buffers=15
title.show.buffers=1

line.margin.visible=1
line.margin.width=4
margin.width=0

are.you.sure.on.reload=1
check.if.already.open=0
default.file.ext=.txt
title.full.path=1
strip.trailing.spaces=1

# Schriften ein wenig größer machen:
if PLAT_WIN
    font.monospace=font:Courier New,size:11
if PLAT_GTK
    font.monospace=font:!Bitstream Vera Sans Mono,size:11

# Alle Schriften auf monospace setzen:
# siehe: http://scintilla.sourceforge.net/SciTEFAQ.html#FixedWidth
font.base=$(font.monospace)
font.small=$(font.monospace)
font.comment=$(font.monospace)
font.text=$(font.monospace)
font.text.comment=$(font.monospace)
font.embedded.base=$(font.monospace)
font.embedded.comment=$(font.monospace)
font.vbs=$(font.monospace)

# Tabulatoren speziell für Python einrichten
# Größe der Tabs: 8 Spaces (Damit sie unterschiedlich sind zu den 4 Spaces)
tabsize=8
indent.size=4
use.tabs=0

# End-Of-Line Zeichen immer nur \n verwenden (CGI-Programmierung)
eol.mode=LF
eol.auto=1
clear.before.execute=1
are.you.sure.on.reload=1

# Automatisch einrücken
indent.automatic=1
indent.opening=1
indent.closing=0
tab.indents=1
backspace.unindents=1

# Einrückungsfehler zeigen
tab.timmy.whinge.level=1

# Autocomplete eischalten
autocompleteword.automatic=1


font.base=$(font.monospace)
font.small=$(font.monospace)
font.comment=$(font.monospace)
font.text=$(font.monospace)
font.text.comment=$(font.monospace)
font.embedded.base=$(font.monospace)
font.embedded.comment=$(font.monospace)
font.vbs=$(font.monospace)

Debugger für SciTE

Damit man beim ausführen von Python Skripten mit F5 auch die Variablen bei einem Traceback sieht, nutzte ich ein keines debugger Skript.

Und hier ein Test skript:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def sub_func():
    foo = 1
    bar = "Python ist cool!"
    raise RuntimeError("Das ist nur ein TEST!!!")

def test():
    foo = 2
    bar = "Python ist..."
    sub_func()


if __name__ == '__main__':
    test()

Die Ausgabe in SciTE sieht dann ca. so aus:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
>pythonw -u c:\python\SciTE_python_debugger.py "c:\python\SciTE_python_debugger_test.py"
Start 'SciTE_python_debugger_test.py' ('c:\python'):
Traceback (most recent call last):
  File "c:\python\SciTE_python_debugger.py", line 121, in <module>
    execfile(filename, locals_globals, locals_globals)
  File "SciTE_python_debugger_test.py", line 15, in <module>
    test()
  File "SciTE_python_debugger_test.py", line 11, in test
    sub_func()
  File "SciTE_python_debugger_test.py", line 8, in sub_func
    raise RuntimeError("Das ist nur ein TEST!!!")
RuntimeError: Das ist nur ein TEST!!!

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Locals by frame, innermost last

 *** Frame <module> in SciTE_python_debugger_test.py at line 15
                        test =  <function test at 0x01F174B0>
                    sub_func =  <function sub_func at 0x01F17570>

 *** Frame test in SciTE_python_debugger_test.py at line 41
	                 foo =  2
	                 bar =  'Python ist...'

 *** Frame sub_func in SciTE_python_debugger_test.py at line 36
	                 foo =  1
	                 bar =  'Python ist cool!'
>Exit code: 0

Das ist echt super hilfreich, finde ich!

Inhalt von SciTE_python_debugger.py für bessere Tracebacks:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# coding: utf-8

"""
    origin code from:
    https://code.google.com/p/scite-files/wiki/Customization_PythonDebug
    http://code.activestate.com/recipes/52215/
"""

import os
import sys
import traceback

def print_exc_plus():
    """
    Print the usual traceback information, followed by a listing of all the
    local variables in each frame.
    """
    tb = sys.exc_info()[2]
    while 1:
        if not tb.tb_next:
            break
        tb = tb.tb_next
    stack = []
    f = tb.tb_frame
    while f:
        stack.append(f)
        f = f.f_back
    stack.reverse()
    traceback.print_exc()
    print
    print " -"*40
    print "Locals by frame, innermost last"
    for frame in stack[1:]:
        print
        print " *** Frame %s in %s at line %s" % (frame.f_code.co_name,
                                             frame.f_code.co_filename,
                                             frame.f_lineno)
        for key, value in frame.f_locals.items():
            if key.startswith("__"):
                continue
            print "\t%20s = " % key,
            #We have to be careful not to cause a new error in our error
            #printer! Calling str() on an unknown object could cause an
            #error we don't want.
            try:
                print repr(value)
            except:
                print "<ERROR WHILE PRINTING VALUE>"


if False:
    #A simplistic demonstration of the kind of problem this approach can help
    #with. Basically, we have a simple function which manipulates all the
    #strings in a list. The function doesn't do any error checking, so when
    #we pass a list which contains something other than strings, we get an
    #error. Figuring out what bad data caused the error is easier with our
    #new function.

    data = ["1", "2", 3, "4"] #Typo: We 'forget' the quotes on data[2]
    def pad4(seq):
        """
        Pad each string in seq with zeros, to four places. Note there
        is no reason to actually write this function, Python already
        does this sort of thing much better.
        Just an example.
        """
        return_value = []
        for thing in seq:
            return_value.append("0" * (4 - len(thing)) + thing)
        return return_value

    #First, show the information we get from a normal traceback.print_exc().
    try:
        pad4(data)
    except:
        traceback.print_exc()
    print
    print "----------------"
    print

    #Now with our new function. Note how easy it is to see the bad data that
    #caused the problem. The variable 'thing' has the value 3, so we know
    #that the TypeError we got was because of that. A quick look at the
    #value for 'data' shows us we simply forgot the quotes on that item.
    try:
        pad4(data)
    except:
        print_exc_plus()


if __name__ == '__main__':
    filepath, filename =  os.path.split(sys.argv[1])
    print "Start %r (%r):" % (filename, filepath)

    os.chdir(filepath)
    current_dir = os.getcwd()
    sys.path.insert(0, current_dir)

    locals_globals = {
        '__builtins__': __builtins__,
        '__name__': '__main__',
        '__file__': filename, # skript should see this "own" filename
    }

    try:
        execfile(filename, locals_globals, locals_globals)
    except SystemExit:
        pass
    except:
        print_exc_plus()

Zum installieren, das debugger Skript SciTE_python_debugger.py irgendwo speichern und in SciTEUser.properties das unten anfügen:

1
2
3
4
if PLAT_WIN
    command.go.*.py=python -u C:\path\to\this\SciTE_python_debugger.py "$(FilePath)"
if PLAT_GTK
    command.go.*.py=python -u /path/to/this/SciTE_python_debugger.py "$(FilePath)"