trace a script

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
be_veronic
User
Beiträge: 16
Registriert: Mittwoch 19. Januar 2005, 23:30

Ich will den Trace von einen grössen Funktion oder einen Script erstellen,aber die Ausgabe ist viel zu gross.Ich benutze sys.settrace() aber ich will etwas sinvolles bekommen die man folgen kann.
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Was meinst du mit folgen?
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Gast

Vielleicht kannst du mir erklaeren was die sys.settrace() Funktion eigentlich macht.Ich moechte z.B den Trace einem Skript erstellen der mit einer .ini Datei arbeitet.Wie sollte die Ausgabe aussehen?

Hier ist ein Teil der Ausgabe...vielleicht hilft das:

20.1.2005 13:37:48] (l) match=[<function match at 0x12b0d8>]
[20.1.2005 13:37:48] (l) _subx=[<function _subx at 0x12b420>]
[20.1.2005 13:37:48] (l) template=[<function template at 0x12b2d0>]
[20.1.2005 13:37:48] (l) I=[2]
[20.1.2005 13:37:48] (l) __file__=[/usr/local/lib/python2.2/sre.pyc]
[20.1.2005 13:37:48] (l) M=[8]
[20.1.2005 13:37:48] (l) L=[4]
[20.1.2005 13:37:48] (l) _join=[<function _join at 0x12b340>]
[20.1.2005 13:37:48] (l) IGNORECASE=[2]
[20.1.2005 13:37:48] (l) S=[16]
[20.1.2005 13:37:48] (l) U=[32]
[20.1.2005 13:37:48] (l) T=[1]
[20.1.2005 13:37:48] (l) sre_parse=[<module 'sre_parse' from '/usr/local/lib/python2.2/sre_parse.pyc'>]
[20.1.2005 13:37:48] (l) DEBUG=[128]
[20.1.2005 13:37:48] (l) __name__=[sre]
[20.1.2005 13:37:48] (l) Scanner=[sre.Scanner]
[20.1.2005 13:37:48] (l) search=[<function search at 0x12b110>]
[20.1.2005 13:37:48] (l) VERBOSE=[64]
[20.1.2005 13:37:48] (l) _pickle=[<function _pickle at 0x12b458>]
[20.1.2005 13:37:48] (l) purge=[<function purge at 0x12b298>]
[20.1.2005 13:37:48] (l) _MAXCACHE=[100]
[20.1.2005 13:37:48] (l) TEMPLATE=[1]
[20.1.2005 13:37:48] (l) MULTILINE=[8]
[20.1.2005 13:37:48] (l) p=[<_sre.SRE_Pattern object at 0x1be860>]
[20.1.2005 13:37:48] (l) key=[('(?P<option>[^:=\\s][^:=]*)\\s*(?P<vi>[:=])\\s*(?P<value>.*)$', 0)]
[20.1.2005 13:37:48] (l) pattern=[(?P<option>[^:=\s][^:=]*)\s*(?P<vi>[:=])\s*(?P<value>.*)$]
[20.1.2005 13:37:48] /var/tmp/python-2.2.2-root/usr/local/lib/python2.2/sre.py(230)
[20.1.2005 13:37:48] /var/tmp/python-2.2.2-root/usr/local/lib/python2.2/sre.py(232)
[20.1.2005 13:37:48] /var/tmp/python-2.2.2-root/usr/local/lib/python2.2/sre.py(233)
[20.1.2005 13:37:48] (l) UNICODE=[32]
[20.1.2005 13:37:48] (l) finditer=[<function finditer at 0x12b228>]
[20.1.2005 13:37:48] (l) _expand=[<function _expand at 0x12b3e8>]
[20.1.2005 13:37:48] (l) sre_compile=[<module 'sre_compile' from '/usr/local/lib/python2.2/sre_compile.pyc'>]
[20.1.2005 13:37:48] (l) LOCALE=[4]
[20.1.2005 13:37:48] (l) X=[64]
[20.1.2005 13:37:48] (l) escape=[<function escape at 0x12b308>]
[20.1.2005 13:37:48] (l) subn=[<function subn at 0x12b180>]
[20.1.2005 13:37:48] (l) _cache=[{('\\[(?P<header>[^]]+)\\]', 0): <_sre.SRE_Pattern object at 0x1b8768>, ('(?P<option>[^:=\\s][^:=]*)\\s*(?P<vi>[:=])\\s*(?P<value>.*)$', 0): <_sre.SRE_Pattern object at 0x1be860>}]
[20.1.2005 13:37:48] (l) findall=[<function findall at 0x12b1f0>]
[20.1.2005 13:37:48] (l) string=[<module 'string' from '/usr/local/lib/python2.2/string.pyc'>]
[20.1.2005 13:37:48] (l) DOTALL=[16]
[20.1.2005 13:37:48] (l) compile=[<function compile at 0x12b260>]
[20.1.2005 13:37:48] (l) sub=[<function sub at 0x12b148>]
[20.1.2005 13:37:48] (l) __all__=[['match', 'search', 'sub', 'subn', 'split', 'findall', 'compile', 'purge', 'template', 'escape', 'I', 'L', 'M', 'S', 'X', 'U', 'IGNORECASE', 'LOCALE', 'MULTILINE', 'DOTALL', 'VERBOSE', 'UNICODE', 'error', 'finditer']]
[20.1.2005 13:37:48] (l) copy_reg=[<module 'copy_reg' from '/usr/local/lib/python2.2/copy_reg.pyc'>]
[20.1.2005 13:37:48] (l) _pattern_type=[<type '_sre.SRE_Pattern'>]
[20.1.2005 13:37:48] (l) _compile_repl=[<function _compile_repl at 0x12b3b0>]
[20.1.2005 13:37:48] (l) split=[<function split at 0x12b1b8>]
[20.1.2005 13:37:48] (l) _cache_repl=[{}]
[20.1.2005 13:37:48] (l) _compile=[<function _compile at 0x12b378>]
[20.1.2005 13:37:48] (l) __version__=[2.2.1]
[20.1.2005 13:37:48] (l) __doc__=[Support for regular expressions (RE).

This module provides regular expression matching operations similar to
those found in Perl. It supports both 8-bit and Unicode strings; both
the pattern and the strings being processed can contain null bytes and
characters outside the US ASCII range.

Regular expressions can contain both special and ordinary characters.
Most ordinary characters, like "A", "a", or "0", are the simplest
regular expressions; they simply match themselves. You can
concatenate ordinary characters, so last matches the string 'last'.

The special characters are:
"." Matches any character except a newline.
"^" Matches the start of the string.
"$" Matches the end of the string.
"*" Matches 0 or more (greedy) repetitions of the preceding RE.
Greedy means that it will match as many repetitions as possible.
"+" Matches 1 or more (greedy) repetitions of the preceding RE.
"?" Matches 0 or 1 (greedy) of the preceding RE.
*?,+?,?? Non-greedy versions of the previous three special characters.
{m,n} Matches from m to n repetitions of the preceding RE.
{m,n}? Non-greedy version of the above.
"\\" Either escapes special characters or signals a special sequence.
[] Indicates a set of characters.
A "^" as the first character indicates a complementing set.
"|" A|B, creates an RE that will match either A or B.
(...) Matches the RE inside the parentheses.
The contents can be retrieved or matched later in the string.
(?iLmsux) Set the I, L, M, S, U, or X flag for the RE (see below).
(?:...) Non-grouping version of regular parentheses.
(?P<name>...) The substring matched by the group is accessible by name.
(?P=name) Matches the text matched earlier by the group named name.
(?#...) A comment; ignored.
(?=...) Matches if ... matches next, but doesn't consume the string.
(?!...) Matches if ... doesn't match next.

The special sequences consist of "\\" and a character from the list
below. If the ordinary character is not on the list, then the
resulting RE will match the second character.
\number Matches the contents of the group of the same number.
\A Matches only at the start of the string.
\Z Matches only at the end of the string.
\b Matches the empty string, but only at the start or end of a word.
\B Matches the empty string, but not at the start or end of a word.
\d Matches any decimal digit; equivalent to the set [0-9].
\D Matches any non-digit character; equivalent to the set [^0-9].
\s Matches any whitespace character; equivalent to [ \t\n\r\f\v].
\S Matches any non-whitespace character; equiv. to [^ \t\n\r\f\v].
\w Matches any alphanumeric character; equivalent to [a-zA-Z0-9_].
With LOCALE, it will match the set [0-9_] plus characters defined
as letters for the current locale.
\W Matches the complement of \w.
\\ Matches a literal backslash.

This module exports the following functions:
match Match a regular expression pattern to the beginning of a string.
search Search a string for the presence of a pattern.
sub Substitute occurrences of a pattern found in a string.
subn Same as sub, but also return the number of substitutions made.
split Split a string by the occurrences of a pattern.
findall Find all occurrences of a pattern in a string.
compile Compile a pattern into a RegexObject.
purge Clear the regular expression cache.
escape Backslash all non-alphanumerics in a string.

Some of the functions in this module takes flags as optional parameters:
I IGNORECASE Perform case-insensitive matching.
L LOCALE Make \w, \W, \b, \B, dependent on the current locale.
M MULTILINE "^" matches the beginning of lines as well as the string.
"$" matches the end of lines as well as the string.
S DOTALL "." matches any character at all, including the newline.
X VERBOSE Ignore whitespace and comments for nicer looking RE's.
U UNICODE Make \w, \W, \b, \B, dependent on the Unicode locale.

This module also defines an exception 'error'.

]
[20.1.2005 13:37:49] (l) match=[<function match at 0x12b0d8>]
[20.1.2005 13:37:49] (l) _subx=[<function _subx at 0x12b420>]
[20.1.2005 13:37:49] (l) template=[<function template at 0x12b2d0>]
[20.1.2005 13:37:49] (l) I=[2]
[20.1.2005 13:37:49] (l) __file__=[/usr/local/lib/python2.2/sre.pyc]
[20.1.2005 13:37:49] (l) M=[8]
[20.1.2005 13:37:49] (l) L=[4]
[20.1.2005 13:37:49] (l) _join=[<function _join at 0x12b340>]
[20.1.2005 13:37:49] (l) IGNORECASE=[2]
[20.1.2005 13:37:49] (l) S=[16]
[20.1.2005 13:37:49] (l) U=[32]
[20.1.2005 13:37:49] (l) T=[1]
[20.1.2005 13:37:49] (l) sre_parse=[<module 'sre_parse' from '/usr/local/lib/python2.2/sre_parse.pyc'>]
[20.1.2005 13:37:49] (l) DEBUG=[128]
[20.1.2005 13:37:49] (l) __name__=[sre]
[20.1.2005 13:37:49] (l) Scanner=[sre.Scanner]
[20.1.2005 13:37:49] (l) search=[<function search at 0x12b110>]
[20.1.2005 13:37:49] (l) VERBOSE=[64]
[20.1.2005 13:37:49] (l) _pickle=[<function _pickle at 0x12b458>]
[20.1.2005 13:37:49] (l) purge=[<function purge at 0x12b298>]
[20.1.2005 13:37:49] (l) _MAXCACHE=[100]
[20.1.2005 13:37:49] (l) TEMPLATE=[1]
[20.1.2005 13:37:49] (l) MULTILINE=[8]
[20.1.2005 13:37:49] (l) pattern=[(?P<option>[^:=\s][^:=]*)\s*(?P<vi>[:=])\s*(?P<value>.*)$]
[20.1.2005 13:37:49] (l) InterpolationError=[ConfigParser.InterpolationError]
[20.1.2005 13:37:49] (l) DEFAULTSECT=[DEFAULT]
[20.1.2005 13:37:49] (l) __all__=[['NoSectionError', 'DuplicateSectionError', 'NoOptionError', 'InterpolationError', 'InterpolationDepthError', 'ParsingError', 'MissingSectionHeaderError', 'ConfigParser', 'DEFAULTSECT', 'MAX_INTERPOLATION_DEPTH']]
[20.1.2005 13:37:49] (l) InterpolationDepthError=[ConfigParser.InterpolationDepthError]
[20.1.2005 13:37:49] (l) MissingSectionHeaderError=[ConfigParser.MissingSectionHeaderError]
[20.1.2005 13:37:49] (l) __file__=[/usr/local/lib/python2.2/ConfigParser.pyc]
[20.1.2005 13:37:49] (l) DuplicateSectionError=[ConfigParser.DuplicateSectionError]
[20.1.2005 13:37:49] (l) NoOptionError=[ConfigParser.NoOptionError]
[20.1.2005 13:37:49] (l) re=[<module 're' from '/usr/local/lib/python2.2/re.pyc'>]
[20.1.2005 13:37:49] (l) MAX_INTERPOLATION_DEPTH=[10]
[20.1.2005 13:37:49] (l) ParsingError=[ConfigParser.ParsingError]
[20.1.2005 13:37:49] (l) Error=[ConfigParser.Error]
[20.1.2005 13:37:49] (l) __name__=[ConfigParser]
[20.1.2005 13:37:49] (l) NoSectionError=[ConfigParser.NoSectionError]
[20.1.2005 13:37:49] (l) __doc__=[Configuration file parser.
Gast

Kennst du eine andere Methode einen Skript zu debugging..der konkreter(weniger) Ausgabe gibt...die man nachvollziehen kann?Das wuerde mir helfen.
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Aus der online Hilfe zum Modul sys:
Python 2.4 Online Dokumentation hat geschrieben:settrace(tracefunc)
Set the system's trace function, which allows you to implement a Python source code debugger in Python. See section 9.2, ``How It Works,'' in the chapter on the Python debugger. The function is thread-specific; for a debugger to support multiple threads, it must be registered using settrace() for each thread being debugged. Note: The settrace() function is intended only for implementing debuggers, profilers, coverage tools and the like. Its behavior is part of the implementation platform, rather than part of the language definition, and thus may not be available in all Python implementations.
Zum debuggen kannst du den pdb nutzen, oder auch den HAP Debugger. Alternativ auch WingIDE, Komodo oder DrPython (ein besserer Debugger ist geplant).
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Dookie
Python-Forum Veteran
Beiträge: 2010
Registriert: Freitag 11. Oktober 2002, 18:00
Wohnort: Salzburg
Kontaktdaten:

Hi be_veronic,

die einfachste Möglichkeit zum Debuggen von Fehlerhaftem Code, sind print-Statements die kritische/interessante Variablen auf der Console ausgeben.


Gruß

Dookie
[code]#!/usr/bin/env python
import this[/code]
Francesco_not_logged_in

Leonidas hat geschrieben:
Zum debuggen kannst du den pdb nutzen, oder auch den HAP Debugger. Alternativ auch WingIDE, Komodo oder DrPython (ein besserer Debugger ist geplant).
Also Hap Debugger habe ich selbst schon probiert, und ist sehr gut.
Er ähnelt dem Visual C++ debugger und hat auch die gleichen shortcuts.
Leider ist dieser nur für Windows verfügbar.

Du kannst auch BOA Constructor verwenden (ich selber bin damit
nicht ganz glücklich geworden).

Diese beiden sind im Gegensatz zu WingIDE oder Komodo
kostenlos und Open Source. (habe Komodo heruntergeladen und hat 30 Tage trial mode ohne Einschränkungen, soweit ich das gesehen habe).

Das mit dem Debugger unter DrPython: da ist es leider wieder
ein bisschen stiller geworden. :(
Antworten