I'm working on framework for testing some command line utilities. I want to create some classes to hold the different types of information more easily.
我正在研究测试一些命令行实用程序的框架。我想创建一些类来更容易地保存不同类型的信息。
Python is fairly new to me so I'm not sure how you would handle this. Do you keep all your classes in one file with your main script or can you separate them into their own files and use them in your main script.
Python对我来说相当新,所以我不确定你将如何处理它。您是否使用主脚本将所有类保存在一个文件中,或者将它们分成自己的文件并在主脚本中使用它们。
What is the paradigm for how you create multiple classes and use them in a single script?
如何创建多个类并在单个脚本中使用它们的范例是什么?
Duplicate of How many python classes should I put in one file
重复一下我应该在一个文件中放入多少个python类
3 个解决方案
#1
2
"What is the paradigm for how you create multiple classes and use them in a single script?"
“如何创建多个类并在单个脚本中使用它们的范例是什么?”
Are you asking about the import statement?
你在询问进口声明吗?
#2
2
An answer from the duplicate question in the comments seems to answer my question. My understanding now is that you can add multiple classes to a separate file which would then be referred to as a module. Then you can import that module to use your classes.
评论中的重复问题的答案似乎回答了我的问题。我现在的理解是你可以将多个类添加到一个单独的文件中,然后将其称为模块。然后,您可以导入该模块以使用您的类。
#3
0
I spread functionality out into separate files as it makes sense, using a modular approach.
我使用模块化方法将功能扩展到单独的文件中。
#1
2
"What is the paradigm for how you create multiple classes and use them in a single script?"
“如何创建多个类并在单个脚本中使用它们的范例是什么?”
Are you asking about the import statement?
你在询问进口声明吗?
#2
2
An answer from the duplicate question in the comments seems to answer my question. My understanding now is that you can add multiple classes to a separate file which would then be referred to as a module. Then you can import that module to use your classes.
评论中的重复问题的答案似乎回答了我的问题。我现在的理解是你可以将多个类添加到一个单独的文件中,然后将其称为模块。然后,您可以导入该模块以使用您的类。
#3
0
I spread functionality out into separate files as it makes sense, using a modular approach.
我使用模块化方法将功能扩展到单独的文件中。