I have a python file named Point2.py, which has the following code
class Point():
def __init__(self,x=0,y=0):
self.x = x
self.y = y
def __str__(self):
return "%d,%d" %(self.x,self.y)
Now in the interpreter, I did this:
>>> import Point2
>>> p1 = Point()
But I received an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
The Point2.py file has Point class in it. Why I am not able to assign it to p1. When I tried:
>>> from Point import *
>>> p1 = Point()
It works
I renamed the file to Point.py and then I did
>>> import Point
>>> p1 = Point
and this works, but assigning values are not easy.
However,
>>> from Point import *
>>> p1 = Point(3,4)
works.
My question is why it behaves differently when I import Point and when I did from Point import *. Which way of importing is a good style?
And is there any relevance for class and the filename?