1
class MyIntroduction:

    def __init__(self, name ,age,education,masters,interestArea):
      self.name = name
      self.age = age
      self.education = education
      self.masters = masters
      self.interestArea = interestArea
    def displayInformation(self):
        print({'name': self.name, 'a': self.age, 'e': self.education, 'M': self.masters, 'IA': self.InterestArea })

emp = { 'emp1': MyIntroduction.__init__("Terex", "92", "BE", "MA", "Sports")}
emp1.displayInformation(self)
NickD
  • 5,937
  • 1
  • 21
  • 38
Reaper15
  • 13
  • 3
  • Please let me know, how to resolve this attribute error and print the details of employee. – Reaper15 Sep 17 '18 at 03:56
  • Possible duplicate of [AttributeError: 'module' object has no attribute](https://stackoverflow.com/questions/1250103/attributeerror-module-object-has-no-attribute) – ThoFin Sep 17 '18 at 03:58

2 Answers2

0

Ok This is how I would do it.

Try This:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# =============================================================================
"""Doc PlaceHolder."""
# =============================================================================


class MyIntroduction():
    """Doc PlaceHolder."""

    def __init__(self):
        """Doc PlaceHolder."""
        self.name = ""
        self.age = ""
        self.education = ""
        self.masters = ""
        self.interestarea = ""

    def set_info(self, name, age, education, masters, interestarea):
        """Doc PlaceHolder."""
        self.name = name
        self.age = age
        self.education = education
        self.masters = masters
        self.interestarea = interestarea

    def displayinformation(self):
        """Doc PlaceHolder."""
        a = {'name': self.name,
             'a': self.age,
             'e': self.education,
             'M': self.masters,
             'IA': self.interestarea
             }
        print(a)

a = MyIntroduction()
a.set_info('Jay', 453, 'SelfTaught', 'Making Stuff Up', 'Space Captain')
a.displayinformation()

Note, the ending of the code.

Use the initializer to set the defaults, then create a method to set or update. Then for ease of reading I created a separate method to set/update your self.variables then split your dict to a variable then printed that.

Results:

python3 testy.py 
{'name': 'Jay', 'a': 453, 'e': 'SelfTaught', 'M': 'Making Stuff Up', 'IA': 'Space Captain'}

Helpful hints: Try using a text editor with syntax highlighting as that will help you learn and remember to format minimize these errors for you =)

I'm still learning myself so, I have no doubt you will get more interesting answers, none the less, this is what I did with your code example.

JayRizzo
  • 3,234
  • 3
  • 33
  • 49
0

You have several mistakes, but there is no need to go the way that @JayRizzo went:

There is a typo in the displayInformation method: InterestArea should be interestArea - note the lower-case initial i. Other than that, the definition of the class is fine.

The main problem is the use of the class: the way you should have used it is to instantiate the class (i.e. define an object of that type):

emp =  MyIntroduction("Terex", "92", "BE", "MA", "Sports")

and then have the object invoke the displayInformation() method to display itself:

emp.displayInformation()

Note that __init__ should not appear explicitly when you instantiate and that self should not appear explicitly outside the class: when an object invokes a class method (e.g. emp.displayInformation(), the object is passed to the method implicitly. That's what self refers to inside the class definition: the object which invoked the class method.

NickD
  • 5,937
  • 1
  • 21
  • 38