Python编程:sys模块

简介: Python编程:sys模块

常用属性

import sys
print(sys.argv)  # 命令行参数list,第一个元素是程序本身路径
print(sys.version)  # python解释器版本 3.4.1
print(sys.maxsize)  # 最大值 9223372036854775807
print(sys.path)  # 返回模块的搜索路径
print(sys.platform)  # 返回操作系统平台名称win32
sys.stdout.write("hello")
val = sys.stdin.readline()[:-1]
print("val",val)

help(sys)

Dynamic objects:


argv -- command line arguments; argv[0] is the script pathname if known
path -- module search path; path[0] is the script directory, else ''
modules -- dictionary of loaded modules
displayhook -- called to show results in an interactive session
excepthook -- called to handle any uncaught exception other than SystemExit
  To customize printing in an interactive session or to install a custom
  top-level exception handler, assign other functions to replace these.
stdin -- standard input file object; used by input()
stdout -- standard output file object; used by print()
stderr -- standard error object; used for error messages
  By assigning other file objects (or objects that behave like files)
  to these, it is possible to redirect all of the interpreter's I/O.
last_type -- type of last uncaught exception
last_value -- value of last uncaught exception
last_traceback -- traceback of last uncaught exception
  These three are only available in an interactive session after a
  traceback has been printed.

Static objects:


builtin_module_names -- tuple of module names built into this interpreter
copyright -- copyright notice pertaining to this interpreter
exec_prefix -- prefix used to find the machine-specific Python library
executable -- absolute path of the executable binary of the Python interpreter
float_info -- a struct sequence with information about the float implementation.
float_repr_style -- string indicating the style of repr() output for floats
hash_info -- a struct sequence with information about the hash algorithm.
hexversion -- version information encoded as a single integer
implementation -- Python implementation information.
int_info -- a struct sequence with information about the int implementation.
maxsize -- the largest supported length of containers.
maxunicode -- the value of the largest Unicode codepoint
platform -- platform identifier
prefix -- prefix used to find the Python library
thread_info -- a struct sequence with information about the thread implementation.
version -- the version of this interpreter as a string
version_info -- version information as a named tuple
dllhandle -- [Windows only] integer handle of the Python DLL
winver -- [Windows only] version number of the Python DLL
__stdin__ -- the original stdin; don't touch!
__stdout__ -- the original stdout; don't touch!
__stderr__ -- the original stderr; don't touch!
__displayhook__ -- the original displayhook; don't touch!
__excepthook__ -- the original excepthook; don't touch!

Functions:

displayhook() -- print an object to the screen, and save it in builtins._
excepthook() -- print an exception and its traceback to sys.stderr
exc_info() -- return thread-safe information about the current exception
exit() -- exit the interpreter by raising SystemExit
getdlopenflags() -- returns flags to be used for dlopen() calls
getprofile() -- get the global profiling function
getrefcount() -- return the reference count for an object (plus one :-)
getrecursionlimit() -- return the max recursion depth for the interpreter
getsizeof() -- return the size of an object in bytes
gettrace() -- get the global debug tracing function
setcheckinterval() -- control how often the interpreter checks for events
setdlopenflags() -- set the flags to be used for dlopen() calls
setprofile() -- set the global profiling function
setrecursionlimit() -- set the max recursion depth for the interpreter
settrace() -- set the global debug tracing function

相关文章
|
1天前
|
分布式计算 IDE 开发工具
如何提高 Python 编程效率
Python 是一种易学、易用的编程语言,但是在实际开发中,我们也会遇到各种各样的问题。本文将分享一些实用的技巧,帮助你提高 Python 编程效率。
|
2天前
|
机器学习/深度学习 人工智能 数据挖掘
Python编程中的高级技巧
Python编程中的高级技巧
27 1
|
2天前
|
程序员 Python
在Python编程中,控制结构
在Python编程中,控制结构
14 4
|
2天前
|
XML JSON 数据库
Python编程教程
Python编程教程
8 2
|
17天前
|
缓存 开发者 Python
Python编程中的装饰器技术解析
本文将深入探讨Python编程中的装饰器技术,包括装饰器的基本概念、使用场景以及实际应用案例。通过了解装饰器的原理和灵活运用,读者可以提升代码的可维护性和扩展性,实现更优雅的编程。
|
18天前
|
数据安全/隐私保护 C++ Python
【Python指南 | 第十篇】以题代练掌握Python初阶编程
【Python指南 | 第十篇】以题代练掌握Python初阶编程
34 0
|
19天前
|
机器学习/深度学习 人工智能 算法
【Python】编程练习的解密与实战(四)
【Python】编程练习的解密与实战(四)
22 0
|
19天前
|
Python
解释Python中的并发编程和并行编程之间的区别。
解释Python中的并发编程和并行编程之间的区别。
|
20天前
|
存储 Python
【Python 30天速成计划】4.函数和模块导入
【Python 30天速成计划】4.函数和模块导入
|
21天前
|
机器学习/深度学习 Python
Python “贪吃蛇”游戏,在不断改进中学习pygame编程
Python “贪吃蛇”游戏,在不断改进中学习pygame编程
27 0
Python “贪吃蛇”游戏,在不断改进中学习pygame编程