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

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
würmchen
User
Beiträge: 255
Registriert: Mittwoch 7. November 2007, 14:17

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?
Zuletzt geändert von würmchen am Mittwoch 23. Januar 2008, 11:50, insgesamt 1-mal geändert.
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Code: Alles auswählen

>>> print sys.__doc__
>>> help(sys)
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
CM
User
Beiträge: 2464
Registriert: Sonntag 29. August 2004, 19:47
Kontaktdaten:

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 ...
würmchen
User
Beiträge: 255
Registriert: Mittwoch 7. November 2007, 14:17

danke
Antworten