Seite 1 von 1

[gelöst] __doc__ und \n newlines werden nicht ausgegeben

Verfasst: Mittwoch 23. Januar 2008, 11:36
von würmchen
Hi Leute,
ist es normal, wenn ich in der console eine python session öffne und dort zB import os eingebe, und danach mir den docstring anzeigen lasse, das keine Neuzeilen gedruckt werden? hier mal meine Ausgaben...
>>> import sys
>>> sys.__doc__
"This module provides access to some objects used or maintained by the\ninterpreter and to functions that interact strongly with the interpreter.\n\nDynamic objects:\n\nargv -- command line arguments; argv[0] is the script pathname if known\npath -- module search path; path[0] is the script directory, else ''\nmodules -- dictionary of loaded modules\n\ndisplayhook -- called to show results in an interactive session\nexcepthook -- called to handle any uncaught exception other than SystemExit\n To customize printing in an interactive session or to install a custom\n top-level exception handler, assign other functions to replace these.\n\nexitfunc -- if sys.exitfunc exists, this routine is called when Python exits\n Assigning to sys.exitfunc is deprecated; use the atexit module instead.\n\nstdin -- standard input file object; used by raw_input() and input()\nstdout -- standard output file object; used by the print statement\nstderr -- standard error object; used for error messages\n By assigning other file objects (or objects that behave like files)\n to these, it is possible to redirect all of the interpreter's I/O.\n\nlast_type -- type of last uncaught exception\nlast_value -- value of last uncaught exception\nlast_traceback -- traceback of last uncaught exception\n These three are only available in an interactive session after a\n traceback has been printed.\n\nexc_type -- type of exception currently being handled\nexc_value -- value of exception currently being handled\nexc_traceback -- traceback of exception currently being handled\n The function exc_info() should be used instead of these three,\n......

Wie bekomm ich den dann dazu da ne ordentliche Formatierung anzuzeigen?

Verfasst: Mittwoch 23. Januar 2008, 11:41
von Leonidas

Code: Alles auswählen

>>> print sys.__doc__
>>> help(sys)

Re: __doc__ und \n newlines werden nicht ausgegeben

Verfasst: Mittwoch 23. Januar 2008, 11:46
von CM
Hoi,
würmchen hat geschrieben: ist es normal, wenn ich in der console eine python session öffne und dort zB import os eingebe, und danach mir den docstring anzeigen lasse, das keine Neuzeilen gedruckt werden?
So, wie Du es machst, ja. Du läßt Dir nämlich den ganzen String anzeigen. Das geht so bei jedem String. Willst Du eine formatierte Ausgabe, so geht z. B.

Code: Alles auswählen

>>> print sys.__doc__
# oder 
>>> sys.stdout.write(sys.__doc__)
(Das zweite Beispiel ist nur zur Illustration, so würde man das in einer interaktiven Session natürlich kaum machen.)
Alternativ geht auch:

Code: Alles auswählen

help(sys)
was zwar nicht zwingend dasselbe ist, aber vielleicht, was Du eigentlich gewollt hast.

Gruß,
Christian

edit: Viel zu langsam ...

Verfasst: Mittwoch 23. Januar 2008, 11:50
von würmchen
danke