#πŸ”’ Feedback on my first so called "project"

12 messages Β· Page 1 of 1 (latest)

minor sandal
#

So recently I learned python or like the basics of it at least and I coded a very basic project. Whenever an employee input their code the program writes a log in a .txt file. Right now its very basic I want to add GUI or UI and improve it. Heres the code:https://github.com/DUnfel/Employee-Checker

GitHub

This is my first ever so called "Project" and its purpose is to check if employees are active on working days. *This project has very weak security, as other employees can mark ot...

echo pierBOT
#

@minor sandal

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

limber jackal
#
  • Adding a proper README is always a nice option. Your program is quite simple, so it's not necessary, but showing how the code is used will eventually become useful as you do larger projects.
  • Use with blocks to make sure that files get closed. If you manually call close, that call can be skipped if you forget it in one case, or of an exception happens and causes that call to be skipped.
  • Variables names should be in lower_snake_case, even if they're representing names.
  • Instead of using separate variables for the names, I'd use a dictionary.
  • All those if branches are nearly identical. As a challenge, try combining them by noting what's common and different between them.
minor sandal
frosty canyon
#

Now you don't need to close() employe_file
It will be automatically closed after Python finishes everything inside the with

limber jackal
# minor sandal 1. Im not sure how to use "with" blocks 2. wdym dictionary. Like a list? 3. I do...

Look into a Real Python page on the topic (I'm assuming one exists) or the standard docs. Essentially, they automatically do something when the block is exited. For file, they ensure files are always closed.

Dictionaries are a fundamental structure, like lists. If you haven't learned them yet, you should do that soon. They are very important to understand.

And for the last point, all of the if bodies look nearly identical. You could try to combine them so you aren't duplicating code.

frosty canyon
#

2,

employees = {
"1237": "Dan"
"1235": "John",
"1236": "Jeniffer",
"1238": "Mike",
}

Now you can do employee_name = employees[code] instead of having to type in the name each time

limber jackal
#

For the last point, think about it like this: what happens if the company grows and you get 100+ employees? Are you going to copy and paste a new if to do file writes every time a new employee joins the company?

#

And what heppens if you ever want to change what data gets written? If you have a separate if check for every employee, you'd need to go to every .write call and make duplicate changes in every case. That does not scale well.

echo pierBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.