Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions sal_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import json
import csv

class Employee:
def __init__(self, employee_id, name, position, salary):
self.employee_id = employee_id
class Emplyee:
def __init__(self, emp_id, name, position, salary):
Comment on lines +5 to +6

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: SyntaxError: expected ':' after class definition
Input in 5

Comment on lines +5 to +6

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: SyntaxError: expected ':' after class definition
Input in 5

self.emp_id = emp_id
Comment on lines +6 to +7

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: def init(self, emp_id in 6

Comment on lines +6 to +7

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: def init(self, emp_id in 6

self.name = name
Comment on lines +7 to 8

This comment was marked as spam.

Comment on lines +7 to 8

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: AttributeError: 'Employee' object has no attribute in 7

Comment on lines +7 to 8

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: AttributeError: 'Employee' object has no attribute in 7

self.position = position
self.salary = salary
Expand All @@ -14,7 +14,7 @@ def give_raise(self, amount):

def to_dict(self):
return {
'employee_id': self.employee_id,
'employee_id': self.emp_id,
'name': self.name,
Comment on lines +17 to 18

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: SyntaxError: invalid syntax
Input: ' in 17

Comment on lines +17 to 18

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: SyntaxError: invalid syntax
Input: ' in 17

'position': self.position,
'salary': self.salary
Expand All @@ -29,8 +29,8 @@ def read_employees_from_csv(file_path):
reader = csv.DictReader(file)
for row in reader:
try:
employee = Employee(
employee_id=row['employee_id'],
employee = Emplyee(
emp_id=row['employee_id'],
Comment on lines +32 to +33

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: SyntaxError: expected class or def statement
Input in 32

Comment on lines +32 to +33

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: SyntaxError: expected class or def statement
Input in 32

name=row['name'],
Comment on lines +33 to 34

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: employee_id=row['employee_id in 33

Comment on lines +33 to 34

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: employee_id=row['employee_id in 33

position=row['position'],
salary=float(row['salary'])
Expand All @@ -44,18 +44,19 @@ def save_employees_to_json(employees, output_file):
with open(output_file, 'w') as file:
json.dump([employee.to_dict() for employee in employees], file, indent=4)

def main():
input_file = 'employees.csv'
output_file = 'employees.json'
def main():
input_file = 'employees.csv'
Comment on lines +47 to +48

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: SyntaxError: invalid syntax
Input: print(" in 47

Comment on lines +47 to +48

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: SyntaxError: invalid syntax
Input: print(" in 47

output_file = 'employees.json'
Comment on lines +48 to +49

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment:
Input: output_file = 'employees. in 48

Comment on lines +48 to +49

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment:
Input: output_file = 'employees. in 48


Comment on lines +49 to 50

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: output_file = 'employees.csv'
in 49

Comment on lines +49 to 50

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: output_file = 'employees.csv'
in 49

Comment on lines +49 to 50

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: output_file = 'employees.csv'
in 49

try:
employees = read_employees_from_csv(input_file)
employees = read_employees_from_csv(input_file)
for employee in employees:
Comment on lines +52 to 53

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: employees = read_employees_from_csv in 52

Comment on lines +52 to 53

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: employees = read_employees_from_csv in 52

employee.give_raise(5000) # Give each employee a raise
save_employees_to_json(employees, output_file)
print(f"Employee data has been saved to {output_file}")
employee.give_raise(5000)
save_employees_to_json(employees, output_file)
print(f"Employee data has been saved to {output_file}")
Comment on lines +55 to +56

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented block in 55

Comment on lines +55 to +56

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented block in 55

except Exception as e:
Comment on lines +56 to 57

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented block in 56

Comment on lines +56 to 57

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented block in 56

Comment on lines +56 to 57

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented block in 56

print(f"An error occurred: {e}")
print(f"An error occurred: {e}")

Comment on lines +58 to 59

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented in 58

Comment on lines +58 to 59

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented in 58

Comment on lines +58 to 59

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested comment: IndentationError: expected an indented in 58

if __name__ == "__main__":
main()