1

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 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?

3
  • 1
    "Or is there some easier way to go about this?" What could possibly be easier? Commented May 25, 2011 at 21:45
  • @S.Lott It's easy but for instance in java it would just be Class(variables, here) Commented May 26, 2011 at 2:08
  • I don't see what's dramatically easier about the Java version. If you used from module import Class, the Python would be identical. Commented May 26, 2011 at 2:48

2 Answers 2

2

You create instances like this:

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

This is the canonical way to instantiate Python objects.

Sign up to request clarification or add additional context in comments.

Comments

2

That's fine. Alternatively you can do:

from Class import Class
Class(variables, here)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.