Understanding the dot notation in python

后端 未结 2 1382
情歌与酒
情歌与酒 2021-01-15 09:43

When I import a module, such as sys, I am assuming that I am importing a script, and in order to access its functions, I have to use the dot notation. For example, I want to

2条回答
  •  再見小時候
    2021-01-15 10:01

    The dot is a generic element reference, not merely a function. This says to get the stderr element of sys, then get the write element of stderr. For this to work, stderr must be an object that contains elements, and write must be a function ... since the parentheses mean that we're trying to call write.

    We do have to know the general semantic of each element: which are packages, which are constants, which are functions, etc.

提交回复
热议问题