Storing objects in a dictionary

Program does not recognize Class. Is there a way to upload .py files?

Hi Sheila,

Copy and paste the text of the error message you are getting into your
reply. But my guess is that you might be typing “Class” instead of
“class”. Python is case-sensitive, and the two words are considered
different.

If that is not your error, then try posting the code and error message.
If you put three backticks ``` (not quotation marks) at the start and
end of the code, it should keep the formatting correct. Like this:

class MyThing:
    def __init__(self):
        self.attribute = 123

Thanks,

Steve

The ‘d’ of ‘def’ before add(my employees) is the error message. And nothing happens.
Thanks.

IMG_1771.JPG

image1.jpeg

Got these returns.
Should I send all again but smaller?

icon.png

(Attachment mime-attachment is missing)

Please post (parts of) your code as text next time. Pictures of code make it impossible to copy and paste code to run it and are unreadable for people using a screen reader.

From the picture I gather the problem is you typed

def add(my employees):

The space between my and employees should go.

Class works making object but not making dictionary:

Will send object program.

class Employee:
def init(self, name, idnum, department, jobtitle):
self.__name = name
self.__idnum = idnum
self.__department = department
self.__jobtitle = jobtitle

def set_name(self, name):
self.__name = name
def set_idnum(self, idnum):
self.__idnum = idnum
def set_department(self, department):
self.__department = department
def set_jobtitle(self, jobtitle):
self.__jobtitle = jobtitle

def get_name(self):
return self.__name
def get_idnum(self):
return self.__idnum
def get_department(self):
return self.__department
def get_jobtitle(self):
return self.__jobtitle
def str(self):
return "Name : " + self.__name +
"\nIdnum: " + self.__idnum +
"\nDepartment: " + self.__department +
"\nJobtitle: " + self.__jobtitle

Class to object program:
import employee
def main():
name = input('Enter employee name: ')
idnum = input('Enter employee id: ')
department = input('Enter employee department: ')
jobtitle = input('Enter employee jobtitle: ')

associate = employee.Employee(name, idnum, department, jobtitle)

print(‘Here is the data that you entered:’)
print(‘name:’, associate.get_name())
print(‘idnum:’, associate.get_idnum())
print(‘department:’, associate.get_department())
print(‘jobtitle:’, associate.get_jobtitle())

main()

Please format the code as code. That will help us to help you.

If you are posting via the web interface, the rich text editor has a
button that will treat your pasted text as code, keeping the indentation
and formatting it nicely.

Otherwise the formatting gets mangled and we can’t tell what errors are
in the original and which are introduced by the mangled formatting.

Sorry, I don’t know what the button looks like, but I’m told that the
web interface should be easy to use.

If you are replying by email, surround your code with three backticks at
the start and end. (Not straight quotes ’ but the key under the ~ next
to the 1.)

```
code goes here
```

Thanks.

def main():
name = input('Enter employee name: ')
idnum = input('Enter employee id: ')
department = input('Enter employee department: ')
jobtitle = input('Enter employee jobtitle: ')

associate = employee.Employee(name, idnum,
department, jobtitle)
print('Here is the data that you entered:')
print('name:', associate.get_name())
print('idnum:', associate.get_idnum())
print('department:', associate.get_department())
print('jobtitle:', associate.get_jobtitle())

main()```

This is the class. It works with a simple program but not with object to dictionary. I will send programs in the manner you suggested if the above is correct.

Will use this computer instead of iPhone. Did you get my text from a moment ago?

Lost my contact with you.
Sent e-mails but they all came back. Used my computer for formatting and that may be the reason.