-
Notifications
You must be signed in to change notification settings - Fork 0
Update sal_json.py #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: SyntaxError: expected ':' after class definition |
||
| self.emp_id = emp_id | ||
|
Comment on lines
+6
to
+7
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Sorry, something went wrong.
Comment on lines
+7
to
8
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: SyntaxError: invalid syntax
Comment on lines
+17
to
18
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: SyntaxError: invalid syntax |
||
| 'position': self.position, | ||
| 'salary': self.salary | ||
|
|
@@ -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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: SyntaxError: expected class or def statement
Comment on lines
+32
to
+33
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: SyntaxError: expected class or def statement |
||
| name=row['name'], | ||
|
Comment on lines
+33
to
34
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']) | ||
|
|
@@ -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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: SyntaxError: invalid syntax
Comment on lines
+47
to
+48
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: SyntaxError: invalid syntax |
||
| output_file = 'employees.json' | ||
|
Comment on lines
+48
to
+49
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment:
Comment on lines
+48
to
+49
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: |
||
|
|
||
|
Comment on lines
+49
to
50
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: output_file = 'employees.csv'
Comment on lines
+49
to
50
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: output_file = 'employees.csv'
Comment on lines
+49
to
50
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: output_file = 'employees.csv' |
||
| 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggested comment: IndentationError: expected an indented in 58 |
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
There was a problem hiding this comment.
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