问:如何理解python中的点符号(即".")?例如:sys.stderr.write("Error")
答:一旦导入一个模块比如sys,点符号就可以引用它包含的任何东西,也可以导入包含模块、类、类中的方法、模块中的函数等。
type(sys)
<class 'module'>
sys.stderr
<_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp437'>
type(sys.stderr)
<class '_io.TextIOWrapper'>
type(sys.stderr.write)
<class 'builtin_function_or_method'>
可以使用type()或help()来查看细节。