Note that there are some explanatory texts on larger screens.

plurals
  1. POPython import issue
    primarykey
    data
    text
    <p>So apparently I just don't know how to import things correctly in a Python program. I'm just starting with the language, and it's much different from the Java that I'm used to.</p> <p>Anyway, the main problem is that there's something wrong with how I'm importing packages/modules/classes and I can't seem to figure out what it is. </p> <p>Right now my file structure looks like:</p> <pre><code>-Main Directory main.py -Person (Folder) __init__.py Person.py Student.py </code></pre> <p>Right now my main.py file looks like..</p> <pre><code>from Person import Person from Person import Student if __name__ == '__main__': p = Person.Person("Jim", 20) print(p) s = Student("Jim", 20, "math") print(s) </code></pre> <p>and I keep getting an error of <code>TypeError: 'module' object is not callable</code></p> <p>Have tried changing it to be <code>s = Student.Student("Jim", 20, "Math")</code> but when that happens I end up with an error of <code>TypeError: module.__init__() takes at most 2 arguments (3 given)</code></p> <p>For reference,</p> <p>Person.py:</p> <pre><code>class Person(): def __init__(self, name, age): self.name = name self.age = age def __str__(self): return "My name is {0} and I am {1}".format(self.name, self.age) </code></pre> <p>Student.py:</p> <pre><code>from Person import Person class Student(Person.Person): def __init__(self, name, age, sub): Person.__init__(self,name,age) self.sub = sub </code></pre> <p>No matter what I do to the imports or anything I can seem to change, it all keeps giving me errors. No idea what to do at this point - maybe I just missed the creating of classes and subclasses when it was shown to me, but I can't figure out anything to fix it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload