开发者

Creating new instance objects

开发者 https://www.devze.com 2023-03-08 05:14 出处:网络
I\'m not sure that I\'ve gotten this right. I\'m working on learning Python and I\'m wondering how exactly you call the constructor 开发者_StackOverflow中文版of a class. Currently the class is in it\'

I'm not sure that I've gotten this right. I'm working on learning Python and I'm wondering how exactly you call the constructor 开发者_StackOverflow中文版of a class. Currently the class is in it's own module that is imported in the main file. Is it right to go

Class.Class(variables, here)

Or is there some easier way to go about this?


You create instances like this:

import MyMod
obj = MyMod.MyClass(param1, param2)

This is the canonical way to instantiate Python objects.


That's fine. Alternatively you can do:

from Class import Class
Class(variables, here)
0

精彩评论

暂无评论...
验证码 换一张
取 消