home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / s / sys < prev   
Encoding:
Text File  |  1996-11-14  |  7.0 KB  |  141 lines

  1. <TITLE>sys -- Python library reference</TITLE>
  2. Next: <A HREF="../t/types" TYPE="Next">types</A>  
  3. Prev: <A HREF="../p/python_services" TYPE="Prev">Python Services</A>  
  4. Up: <A HREF="../p/python_services" TYPE="Up">Python Services</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H1>3.1. Built-in Module <CODE>sys</CODE></H1>
  7. This module provides access to some variables used or maintained by the
  8. interpreter and to functions that interact strongly with the interpreter.
  9. It is always available.
  10. <P>
  11. <DL><DT><B>argv</B> -- data of module sys<DD>
  12. The list of command line arguments passed to a Python script.
  13. <CODE>sys.argv[0]</CODE> is the script name (it is operating system
  14. dependent whether this is a full pathname or not).
  15. If the command was executed using the `<SAMP>-c</SAMP>' command line option
  16. to the interpreter, <CODE>sys.argv[0]</CODE> is set to the string
  17. <CODE>"-c"</CODE>.
  18. If no script name was passed to the Python interpreter,
  19. <CODE>sys.argv</CODE> has zero length.
  20. </DL>
  21. <DL><DT><B>builtin_module_names</B> -- data of module sys<DD>
  22. A list of strings giving the names of all modules that are compiled
  23. into this Python interpreter.  (This information is not available in
  24. any other way --- <CODE>sys.modules.keys()</CODE> only lists the imported
  25. modules.)
  26. </DL>
  27. <DL><DT><B>exc_type</B> -- data of module sys<DD>
  28. </DL>
  29. <DL><DT><B>exc_value</B> -- data of module sys<DD>
  30. </DL>
  31. <DL><DT><B>exc_traceback</B> -- data of module sys<DD>
  32. These three variables are not always defined; they are set when an
  33. exception handler (an <CODE>except</CODE> clause of a <CODE>try</CODE> statement) is
  34. invoked.  Their meaning is: <CODE>exc_type</CODE> gets the exception type of
  35. the exception being handled; <CODE>exc_value</CODE> gets the exception
  36. parameter (its <DFN>associated value</DFN> or the second argument to
  37. <CODE>raise</CODE>); <CODE>exc_traceback</CODE> gets a traceback object (see the
  38. Reference Manual) which
  39. encapsulates the call stack at the point where the exception
  40. originally occurred.
  41. </DL>
  42. <DL><DT><B>exit</B> (<VAR>n</VAR>) -- function of module sys<DD>
  43. Exit from Python with numeric exit status <VAR>n</VAR>.  This is
  44. implemented by raising the <CODE>SystemExit</CODE> exception, so cleanup
  45. actions specified by <CODE>finally</CODE> clauses of <CODE>try</CODE> statements
  46. are honored, and it is possible to catch the exit attempt at an outer
  47. level.
  48. </DL>
  49. <DL><DT><B>exitfunc</B> -- data of module sys<DD>
  50. This value is not actually defined by the module, but can be set by
  51. the user (or by a program) to specify a clean-up action at program
  52. exit.  When set, it should be a parameterless function.  This function
  53. will be called when the interpreter exits in any way (except when a
  54. fatal error occurs: in that case the interpreter's internal state
  55. cannot be trusted).
  56. </DL>
  57. <DL><DT><B>last_type</B> -- data of module sys<DD>
  58. </DL>
  59. <DL><DT><B>last_value</B> -- data of module sys<DD>
  60. </DL>
  61. <DL><DT><B>last_traceback</B> -- data of module sys<DD>
  62. These three variables are not always defined; they are set when an
  63. exception is not handled and the interpreter prints an error message
  64. and a stack traceback.  Their intended use is to allow an interactive
  65. user to import a debugger module and engage in post-mortem debugging
  66. without having to re-execute the command that caused the error (which
  67. may be hard to reproduce).  The meaning of the variables is the same
  68. as that of <CODE>exc_type</CODE>, <CODE>exc_value</CODE> and <CODE>exc_tracaback</CODE>,
  69. respectively.
  70. </DL>
  71. <DL><DT><B>modules</B> -- data of module sys<DD>
  72. Gives the list of modules that have already been loaded.
  73. This can be manipulated to force reloading of modules and other tricks.
  74. </DL>
  75. <DL><DT><B>path</B> -- data of module sys<DD>
  76. A list of strings that specifies the search path for modules.
  77. Initialized from the environment variable <CODE>PYTHONPATH</CODE>, or an
  78. installation-dependent default.
  79. </DL>
  80. <DL><DT><B>platform</B> -- data of module sys<DD>
  81. This string contains a platform identifier.  This can be used to
  82. append platform-specific components to <CODE>sys.path</CODE>, for instance.
  83. </DL>
  84. <DL><DT><B>ps1</B> -- data of module sys<DD>
  85. </DL>
  86. <DL><DT><B>ps2</B> -- data of module sys<DD>
  87. Strings specifying the primary and secondary prompt of the
  88. interpreter.  These are only defined if the interpreter is in
  89. interactive mode.  Their initial values in this case are
  90. <CODE>'>>> '</CODE> and <CODE>'... '</CODE>.
  91. </DL>
  92. <DL><DT><B>setcheckinterval</B> (<VAR>interval</VAR>) -- function of module sys<DD>
  93. Set the interpreter's ``check interval''.  This integer value
  94. determines how often the interpreter checks for periodic things such
  95. as thread switches and signal handlers.  The default is 10, meaning
  96. the check is performed every 10 Python virtual instructions.  Setting
  97. it to a larger value may increase performance for programs using
  98. threads.  Setting it to a value  checks every virtual instruction,
  99. maximizing responsiveness as well as overhead.
  100. </DL>
  101. <DL><DT><B>settrace</B> (<VAR>tracefunc</VAR>) -- function of module sys<DD>
  102. Set the system's trace function, which allows you to implement a
  103. Python source code debugger in Python.  See section ``How It Works''
  104. in the chapter on the Python Debugger.
  105. </DL>
  106. <DL><DT><B>setprofile</B> (<VAR>profilefunc</VAR>) -- function of module sys<DD>
  107. Set the system's profile function, which allows you to implement a
  108. Python source code profiler in Python.  See the chapter on the
  109. Python Profiler.  The system's profile function
  110. is called similarly to the system's trace function (see
  111. <CODE>sys.settrace</CODE>), but it isn't called for each executed line of
  112. code (only on call and return and when an exception occurs).  Also,
  113. its return value is not used, so it can just return <CODE>None</CODE>.
  114. </DL>
  115. <DL><DT><B>stdin</B> -- data of module sys<DD>
  116. </DL>
  117. <DL><DT><B>stdout</B> -- data of module sys<DD>
  118. </DL>
  119. <DL><DT><B>stderr</B> -- data of module sys<DD>
  120. File objects corresponding to the interpreter's standard input,
  121. output and error streams.  <CODE>sys.stdin</CODE> is used for all
  122. interpreter input except for scripts but including calls to
  123. <CODE>input()</CODE> and <CODE>raw_input()</CODE>.  <CODE>sys.stdout</CODE> is used
  124. for the output of <CODE>print</CODE> and expression statements and for the
  125. prompts of <CODE>input()</CODE> and <CODE>raw_input()</CODE>.  The interpreter's
  126. own prompts and (almost all of) its error messages go to
  127. <CODE>sys.stderr</CODE>.  <CODE>sys.stdout</CODE> and <CODE>sys.stderr</CODE> needn't
  128. be built-in file objects: any object is acceptable as long as it has
  129. a <CODE>write</CODE> method that takes a string argument.  (Changing these
  130. objects doesn't affect the standard I/O streams of processes
  131. executed by <CODE>popen()</CODE>, <CODE>system()</CODE> or the <CODE>exec*()</CODE>
  132. family of functions in the <CODE>os</CODE> module.)
  133. </DL>
  134. <DL><DT><B>tracebacklimit</B> -- data of module sys<DD>
  135. When this variable is set to an integer value, it determines the
  136. maximum number of levels of traceback information printed when an
  137. unhandled exception occurs.  The default is 1000.  When set to 0 or
  138. less, all traceback information is suppressed and only the exception
  139. type and value are printed.
  140. </DL>
  141.