在 Python 中使用与脚本名称相同的 class 名称会有什么区别?

What difference will it make to use same class name as script name in Python?

我想在 python 脚本中使用与 Python 脚本名称相同的 class 名称。此外,我的脚本中只有一个 class。例如,如果我的脚本结构如下所示:

test.py
  |
  class test(object):
    def __init__(self, var1, var2 ....):
      ...
      ...  

我想了解当我导入此脚本并从其他脚本使用此 class 时会有什么不同?

纯粹从语言的角度来看,除了可能会引起输入 class 的人的一些混淆外,它没有任何区别。

如果您将此模块用作 robotframework 测试套件中的库,那么机器人将自动实例化一个 class 如果它与库文件同名。 class 中的方法将作为该库中的关键字公开。

robotframework 用户指南有一个标题为 Creating test library class or module 的部分(强调我的):

Python classes are always inside a module. If the name of a class implementing a library is the same as the name of the module, Robot Framework allows dropping the class name when importing the library. For example, class MyLib in MyLib.py file can be used as a library with just name MyLib. This also works with submodules so that if, for example, parent.MyLib module has class MyLib, importing it using just parent.MyLib works. If the module name and class name are different, libraries must be taken into use using both module and class names, such as mymodule.MyLibrary or parent.submodule.MyLib.