Reputation: 39698
I'm working on writing my first Python class. Being the java programmer that I am, I have something like this:
#class1.py
class class1:
def __init__(self):
#Do stuff here
And in my current script:
import class1
object = class1()
I'm getting a Name Error: name 'class1' is not defined
I've also tried this, with no luck:
import class1
object = class1.class1()
The error I get here is AttributeError: 'module' object has no attribute 'class1'
What am I doing wrong?
Upvotes: 1
Views: 110
Reputation: 392
Python import is by module and then by the contents of the module, so for your class1.py it becomes:
from class1 import class1
Upvotes: 4
Reputation: 4391
In Python you import the modules. For class1.py file you can use:
from class1 import class1
Or if you have more than one....
from class1 import *
Upvotes: -1