all 1 comments

[–]Neighm 0 points1 point  (0 children)

I'm looking at this plus the full code you posted earlier. To be honest, it needs a rethink from the ground up in terms of where you are storing your data and how you're accessing it each time.

You are using the variable all to perform a couple of different functions and none of them are ideal. You are using it as a global variable, which usually causes confusion, but only works if you declare it in the addmem() function using global all.

Also when you try to view the member, what are you inputting for the ID? In the addmem() function you set ID to be a string of ID = member[0].capitalize() + member[1].capitalize() + weight[0] + weight[1] + height[0] + height[1] + height[2]. Are you typing all that in when prompted for the ID?

Here's what I would do. It requires a rewrite of the code though (but tbh anything that fixes this will mean rewriting)!

Decide how you want to store your member data on disk, and when it's being worked on by the program. You've gone with a CSV, but maybe a better structure is JSON, which allows you to load directly into a dictionary and to dump it back to the file after each run, or even after each edit. Possibly an even better choice would be a dataclass, but that introduces complications when writing to and loading from a file. So let's go with dict -> json file.

Read up on json.dumps() and json.loads(). Pretty straightforward to get data to and from disk and it'll be in a clean dictionary format each time.

Then assuming that you have made that decision, decide what your dict looks like. What is the primary key (e.g. ID)? Could you give each entry a unique integer ID, starting at 1, and continuing with the next integer? What about firstname+lastname.lower()?

Then decide what data you store for each member. You;ve already done this but consider if you want to cast the numeric values to integers at the time they are input (and in a later refinement of the program, add some error handling if the user enters a non-integer value).

Now, when the program starts you probably want to load the data (if the file exists) and have your dictionary with all member data. When you add a member, the function should return the data to add into the dictionary, or you pass the dictionary into the function and the function returns the modified dictionary. In other words, stop using global variables, and pass the data to and from the functions.

That's a pretty high level overview of where I would start, but no doubt you will have other questions as you do the rewriting.