Reputation: 1494
For example, I have package X, which contains modules module1 and module2. In module1 I have a class MyClass, which I want to use in module2. Can I just do this in module2:
import module1
a = module1.MyClass()
?
I mean usage of relative path to module. In python documentation(in " Intra-package References" section) says, that in python2.7 we can use "import module1", but for python 3 they say, that we can use "from module1 import MyClass". But there are no information, is this first form prohibited. And this is my question.
Upvotes: 0
Views: 355
Reputation: 19
Why don't you try it out?
This code won't work. It needs to be
import module1
a = module1.MyClass()
I suggest reading up on packages and import. They can get more confusing when your package starts to grow.
Upvotes: 1