[Tutor] error message
Alan Gauld
alan.gauld at yahoo.co.uk
Thu Mar 21 07:28:48 EDT 2019
On 21/03/19 05:13, Glenn Dickerson wrote:
> Thank you for all of your responses to:
>
> class Student():
> def__init__(self, name, major, gpa, is_on_probation):
> self.name = name
> self.major = major
> self.gpa = gpa
> self.is_on_probation = is_on_probation
>
Presumably the lines above ar in a separate file called Student.py?
And the lines below are in another file called app.py?
If so thats a good start.
Steve (and others have already pointed out the need for a space after
def (otherwise python looks for a function called def__init__() and
wonderswhy yu have a colon after its invocation)
But that will only lead you to the next error.
> import Student
> student1 = Student('Jim', 'Business', 3.1, False)
When accessing an object in an imported module you must precede
the object's name with the module:
student1 = Student.Student(....) # Student class in the Student module
Alternatively you can explicitly import the Student class (and nothing
else!) from Student with:
from Student import Student
I which case you can use it as you do in your code.
In your case it doesn't really matter which of the two styles
you choose. In more complex programs explicit module naming
might make your code clearer (eg. if you have many modules).
Alternatively, pulling in the specific object might save
you some typing if you reference the object several times.
You need to choose which is most appropriate based on your code.
HTH
Alan G.
More information about the Tutor
mailing list